//
SqlConnection sqlConn;
SqlCommand cmdStr;
string sqlStr;
int count;
private void button2_Click(object sender, EventArgs e)
{
string strConn = "server=127.0.0.1;database=ufdata_001_2014;uid=sa;pwd=cs,./123";
sqlConn = new SqlConnection(strConn);
sqlConn.Open();
cmdStr = new SqlCommand(sqlStr,sqlConn);
for (int i = 0; i < listView1.Items.Count; i++)
{
sqlStr = "insert into Test (t_id,t_name,t_time,t_price) values (t_id = @t_id,t_name = @t_name,t_time = @t_time,t_price = @t_price)";
cmdStr.Parameters.Add("@t_id", SqlDbType.Int);
cmdStr.Parameters.Add("@t_name", SqlDbType.NVarChar,50);
cmdStr.Parameters.Add("@t_time", SqlDbType.DateTime);
cmdStr.Parameters.Add("@t_price", SqlDbType.Money);
cmdStr.Parameters["@t_id"].Value = listView1.Items[i].SubItems[0].Text;
cmdStr.Parameters["@t_name"].Value = " + listView1.Items[i].SubItems[1].Text + ";
cmdStr.Parameters["@t_time"].Value = listView1.Items[i].SubItems[2].Text;
cmdStr.Parameters["@t_price"].Value = listView1.Items[i].SubItems[3].Text;
}
if ( cmdStr.ExecuteNonQuery()> 0)
{
MessageBox.Show("新增记录成功!");
sqlConn.Close();
}
else
{
MessageBox.Show("新增失败!");
}
}
为什么提示这个,才学,不太懂,谢谢!
aluckdog
心有法竹