TextBox用逗号隔开,如何将数据循环插入数据库
如上图,选择了两个用户,则需要在数据库插入两条记录,可是运行之后数据库记录如下图所示,插入之后变成了
"system.string[]"
protected void Button4_Click(object sender, EventArgs e)
{
string recuser = this.TextBox1.Text;
string[] str = recuser.Split(',');
string mcontent = TextBox2.Text;
string mtime = DateTime.Now.ToString();
string sender2 = Session["username"].ToString();
int mtype = 0;
string mzht = "new.png";
string sql = "insert into message (recuser,mcontent,mtime,sender,mtype,mzht)values('"+str+"','"+mcontent+"','"+mtime+"','"+sender2+"','"+mtype+"','"+mzht+"')";
try
{
int n;
n = db.Command(sql);
if (n > 0)
{
Response.Write(" <script language=javascript>alert('发送成功!');window.window.location.href='http://localhost:6984/TONGCHUANG/user/sendmessage.aspx';</script>");
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}