I want to use a datagrid item as a variable in an insert statement. I can’t figure out how to convert the string value to varchar.
Here is what I am trying to do.
{
string ord = grdDisplayOrd.Rows[1].Cells[2].Text;
cmd.Parameters.Add("@ord", SqlDbType.VarChar).Value = ord;
}
What am I missing here?
you didn’t supply any error message, but maybe it because you didn’t specified the SqlParameter length.
Anyway, try using
cmd.Parameters.AddWithValue("@ord", ord);it will auto recognized your type.