C#中调用函数的参数更新SQL数据库解决办法
C#中调用函数的参数更新SQL数据库
调用的in_history 函数如下:
我的意思是 如果短信发送成功以后,就将短信的记录放入t_history表中。
但是我测试的时候并没有将成功的短信插入进去,为什么啊。哪儿出错了??
------解决方案--------------------
string newsql = string.Format("update t_history set time = time, type = type, text = text, name = name, number = number");
你上面这条语句没作用。
你这里应该是INSRET INTO 语句。
------解决方案--------------------
拼接字符串,直接上代码
- C# code
private void button_single_Click(object sender, EventArgs e) //个人短信----支持发送单个号码的短信 { label4.Text = "短信发送中..."; string telephone = textBox4.Text.Trim(); //获取电话号码 string message = textBox3.Text.Trim(); //获取短信内容 type = 1; if (CPPDLL.Sms_Send(telephone, message) == 1) //发短信过程,成功返回1,不成功返回0 { label4.Text = "发送成功"; in_history( System.DateTime.Now.ToString(), type, message, "" , telephone);//调用函数 } else { label4.Text = "发送失败"; } }
调用的in_history 函数如下:
- C# code
private void in_history(string time ,int type, string text, string name, string number)//将发送记录插入数据表 { string connString = MessageModem.Properties.Settings.Default.ConnString; SqlConnection sqlConnection = new SqlConnection(connString); sqlConnection.Open(); string newsql = string.Format("update t_history set time = time, type = type, text = text, name = name, number = number"); SqlCommand newcmd = new SqlCommand(newsql, sqlConnection); SqlDataAdapter newdata = new SqlDataAdapter(); newdata.UpdateCommand = newcmd; newcmd.ExecuteNonQuery(); }
我的意思是 如果短信发送成功以后,就将短信的记录放入t_history表中。
但是我测试的时候并没有将成功的短信插入进去,为什么啊。哪儿出错了??
------解决方案--------------------
string newsql = string.Format("update t_history set time = time, type = type, text = text, name = name, number = number");
你上面这条语句没作用。
你这里应该是INSRET INTO 语句。
------解决方案--------------------
拼接字符串,直接上代码
- C# code
string newsql = string.Format("update t_history set time = '{0}', type = '{1}', text = '{2}', name = '{3}', number = '{4}'",time,type,text,name,number);