데이터를 데이터베이스에 저장할 때 오류가 발생합니다. 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);
}
}
}
을 나는 더 이상 내 도움을 필요로하지 않는 것 같아요, 많은 전문가들은 지금 문제 @AbZy 질문 : – AbZy
에 대답하는 것은 [ "측정"을] 박사 = ds.Tables을 찾을 수 있습니다. 행 [0]. 행 0에 아무 위치도 없다. 내가 당신의 지시를 따랐다. –
그냥 btnSave_Click_1이라는 메서드로 데이터베이스 작업을 수행하는 것을 보았을 때 눈이 아팠다. –