I'm sorry. I just noticed you are using a dataset. I never (well hardly ever) use the things, so I'm not sure how much help I can be. It looks like you created a strongly typed dataset elsewhere, but you seem to be trying to execute an INSERT statement on an independant command object ('SQLInsertCommand1'), rather than using the data adapter to do the dataset work for you.
I'm going to ignore the DataSet here.
You should be able to construct the command object and add parameters as:
string addNum =
"INSERT INTO ContactList ([Address], [FullName] ,[DirectLine] ,[Mobile]) "+
"VALUES(@Address, @FullName, @DirectLine, @Mobile)";
sqlInsertCommand1.CommandType = CommandType.Text;
sqlInsertCommand1.CommandText = addNum;
sqlInsertCommand1.Connection = connAdd;
sqlInsertCommand1.Parameters.Add("@Address", SqlDbType.Char, 255).Value = comboBoxDepartment.Text;
...(statements for all the other parameters)
etc
Then execute the command object as:
sqlInsertCommand1.ExecuteNonQuery();
That should add
one row to the table. Note that I dropped the last parameter on the Add call, as that provides a mapping between a dataset column and the parameter. Your use of the .ExecuteNonQuery on the command object to execute the command means it has nothing to do with the dataset, so that last argument doesn't belong there.
To use the command again to add another row, you must not add the parameters again (that's why you got the already in use error). Just set the value of each named parameter appropriately and execute the command object again.
If you want to make use of the dataset's ability to update ALL the modified rows, you shouldn't use the execute method on the command object, but rather the UPDATE method on the DataAdapter.
Doing this, and constructing a strongly type dataset to support it is
way beyond the scope of any discussion we can have here, as that is a .NET/ADO/C# programming issue and not a SQL Server one...
P.S. You probably should use varchar datatypes (instead of char) for your database string data, since I doubt, for example, that an address of yours is exactly 255 characters long. So why store 255 if you usually only need way less than that...
Jeff Mason
Custom Apps, Inc.
[email protected]