可以只看最后这一段代码
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Text = comboBox1.SelectedItem.ToString();
} private void btnNew_Click(object sender, EventArgs e[color=#FF0000])//保存信息到CAD_IP_PatientNotice,就是这里click后,数据库中没有插入数据 [/color]{
try
{
SqlConnection conn5 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\db.mdf;Integrated Security=True;User Instance=True");
conn5.Open();
string strInsert = "INSERT INTO [CAD_IP_PatientNotice] (iPatientID,vPatientName,cPatientSex,iPatientAge,vPatientCellphone,vPatientIdentifyCard,iSpecialPatient,vDiagnose,vAttending)VALUES('" + txtPID.Text + "','" + lblPName.Text + "','" + lblPSex.Text + "','" + lblPAge.Text + "','" + lblPPhone.Text + "','" + lblPID.Text + "','" + lblSpecial.Text + "','" + txtDiagnose.Text + "','" + comboBox1.Text + "')";
SqlCommand cmd5 = new SqlCommand(strInsert, conn5);
DataSet ds5 = new DataSet("CAD_IP_PatientNotice");
SqlDataAdapter sda5 = new SqlDataAdapter(cmd5);
sda5.InsertCommand = new SqlCommand(strInsert, conn5);
sda5.Fill(ds5, "CAD_IP_PatientNotice");
DataTable dt = ds5.Tables["CAD_IP_PatientNotice"];
//SqlCommandBuilder scb5 = new SqlCommandBuilder(sda5);
sda5.Update(ds5.Tables["CAD_IP_PatientNotice"]);
if (cmd5.ExecuteNonQuery() > 0)
{
MessageBox.Show("开单成功!", "提示"); }
else
{
MessageBox.Show("开单失败,请完整填写住院通知单!", "提示");
}
sda5.Dispose();
ds5.Dispose();
dt.Dispose();
conn5.Close();
}
catch (Exception x)
{
MessageBox.Show("错误" + x.ToString(), "error");
}
} }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Text = comboBox1.SelectedItem.ToString();
} private void btnNew_Click(object sender, EventArgs e[color=#FF0000])//保存信息到CAD_IP_PatientNotice,就是这里click后,数据库中没有插入数据 [/color]{
try
{
SqlConnection conn5 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\db.mdf;Integrated Security=True;User Instance=True");
conn5.Open();
string strInsert = "INSERT INTO [CAD_IP_PatientNotice] (iPatientID,vPatientName,cPatientSex,iPatientAge,vPatientCellphone,vPatientIdentifyCard,iSpecialPatient,vDiagnose,vAttending)VALUES('" + txtPID.Text + "','" + lblPName.Text + "','" + lblPSex.Text + "','" + lblPAge.Text + "','" + lblPPhone.Text + "','" + lblPID.Text + "','" + lblSpecial.Text + "','" + txtDiagnose.Text + "','" + comboBox1.Text + "')";
SqlCommand cmd5 = new SqlCommand(strInsert, conn5);
DataSet ds5 = new DataSet("CAD_IP_PatientNotice");
SqlDataAdapter sda5 = new SqlDataAdapter(cmd5);
sda5.InsertCommand = new SqlCommand(strInsert, conn5);
sda5.Fill(ds5, "CAD_IP_PatientNotice");
DataTable dt = ds5.Tables["CAD_IP_PatientNotice"];
//SqlCommandBuilder scb5 = new SqlCommandBuilder(sda5);
sda5.Update(ds5.Tables["CAD_IP_PatientNotice"]);
if (cmd5.ExecuteNonQuery() > 0)
{
MessageBox.Show("开单成功!", "提示"); }
else
{
MessageBox.Show("开单失败,请完整填写住院通知单!", "提示");
}
sda5.Dispose();
ds5.Dispose();
dt.Dispose();
conn5.Close();
}
catch (Exception x)
{
MessageBox.Show("错误" + x.ToString(), "error");
}
} }
SqlCommand cmd5 = new SqlCommand(strInsert, conn5);
conn5.Open();
int rowCount=cmd5.ExecuteNonQuery();
conn5.close();if (rowCount>0)
......
你说的我试过了,貌似不行。
第二,你的sqlconnection string写错了。
string strConn = "server=127.0.0.1;database=TestWebServ;pwd=sa;uid=sa";
Conn.ConnectionString = strConn;
string strSql = "select * from tNodeInfo where ID='" + ID + "' and Password='" + EnKeyCoke + "'";
Conn.Open(); SqlDataAdapter ad = new SqlDataAdapter(strSql, Conn);
ad.Fill(ds);
sda5.InsertCommand = new SqlCommand(strInsert, conn5);
sda5.Fill(ds5, "CAD_IP_PatientNotice");
DataTable dt = ds5.Tables["CAD_IP_PatientNotice"];
//SqlCommandBuilder scb5 = new SqlCommandBuilder(sda5);
sda5.Update(ds5.Tables["CAD_IP_PatientNotice"]);报的是参数空了
还有就是数据库连接字符串用这么多次也不嫌麻烦啊对于标题党,肯定是不可能的,Sql Express也包含一些基础的sql server功能的
赞同
注:一般都不用VS自带的,SQl2005 最好还是自己装一个,
声明,第一,老师要求的VS自带的sql express。
第二,报的错误是system.ArgumentNullException:值不能为空。出错行:datatable
txtPID不是主键,主键我没插