I am doing a sample program where it involves inserting data from textboxes and a Combox to SQL Server databse ...
private void btnAdd_Click(object sender, EventArgs e)
{
da.InsertCommand = new SqlCommand("INSERT INTO Member VALUES (@MemberID, @Name, @Surname, @IDNo, @Address, @Town, @TelNo, @MobNo, @Email)", c);
da.InsertCommand.Parameters.Add("@MemberID", SqlDbType.VarChar).Value = textBox50.Text;
da.InsertCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = textBox49.Text;
da.InsertCommand.Parameters.Add("@Surname", SqlDbType.VarChar).Value = textBox48.Text;
da.InsertCommand.Parameters.Add("@IDNo", SqlDbType.VarChar).Value = textBox47.Text;
da.InsertCommand.Parameters.Add("@Address", SqlDbType.VarChar).Value = textBox46.Text;
da.InsertCommand.Parameters.Add("@Town", SqlDbType.VarChar).Value = comboBox1.SelectedItem;
da.InsertCommand.Parameters.Add("@TelNo", SqlDbType.VarChar).Value = textBox51.Text;
da.InsertCommand.Parameters.Add("@MobNo", SqlDbType.VarChar).Value = textBox52.Text;
da.InsertCommand.Parameters.Add("@Email", SqlDbType.VarChar).Value = textBox53.Text;
c.Open();
da.InsertCommand.ExecuteNonQuery();
MessageBox.Show("Done");
c.Close();
}
The problem is regarding the comboBox ! It is giving me this error when I am adding the data to the SQL Server :
Failed to convert parameter value from a DataRowView to a String.
in the server, the Town is declared as varchar(90) .
please help ! thanks :)