将数据保存到数据库时出错。DataAdapter.Fill(ds,"Table") 在将数据类型 nvarchar 转换为数字时抛出 SqlException 错误。
private void btnSave_Click_1(object sender, EventArgs e)
{
da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from Measurement where ID = @ID", con);
da.SelectCommand.Parameters.AddWithValue("@ID", txtID.Text);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Fill(ds, "Measurement"); //(SqlException Unhandled)Error converting data type nvarchar to numeric.
if (String.IsNullOrEmpty(txtCellNo.Text.Trim()))
{
MessageBox.Show("Please enter Cell Number");
}
else
{
try
{
dr = ds.Tables["Measurement"].Rows[0];
dr["CellNumber"] = txtCellNo.Text.Trim();
dr["FirstName"] = txtFirstName.Text;
dr["LastName"] = txtLastName.Text;
dr["Shirt"] = txtShirt.Text;
dr["Pant"] = txtPant.Text;
dr["DueDate"] = txtDueDate.Text;
dr["Date"] = txtDate.Text;
cb.GetUpdateCommand();
da.Update(ds, "Measurement");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}