控件的值写入sql表问题:
假如控件select1选择‘c#’,textbox1中输入‘工程师’,textbox2中输入‘白雪’,textbox3中输入‘36’,要求在tb的zd字段中写入‘c#工程师’,xm中写入‘白雪’、nl中写入‘36’,下面的代码怎样该?
cmd.CommandText = "INSERT INTO tb(dz,xm,nl) VALUES(???,'" + textbox2.Text + "','" + textbox3.Text + "')"; 就是:select1和textbox1写入dz,textbox2.Text 写入xm,textbox3.Text 写入nl,怎么办?请各位帮忙。
假如控件select1选择‘c#’,textbox1中输入‘工程师’,textbox2中输入‘白雪’,textbox3中输入‘36’,要求在tb的zd字段中写入‘c#工程师’,xm中写入‘白雪’、nl中写入‘36’,下面的代码怎样该?
cmd.CommandText = "INSERT INTO tb(dz,xm,nl) VALUES(???,'" + textbox2.Text + "','" + textbox3.Text + "')"; 就是:select1和textbox1写入dz,textbox2.Text 写入xm,textbox3.Text 写入nl,怎么办?请各位帮忙。
select1是控件的id还是name?
StringBuilder sb = new StringBuilder("insert in tb(dz,xm,nl) values('[AAA]','[BBB]','[CCC]')");
sb.replace("[AAA]",textbox1.Text);
sb.replace("[BBB]",textbox2.Text);
sb.replace("[CCC]",textbox3.Text);
cmd.CommandText = sb.ToString();
这么写: cmd.CommandText = "INSERT INTO tb(dz,xm,nl) VALUES('"+Select1.SelectedItem.Text.ToString()+ textbox2.Text + "','" + textbox3.Text + "')";
<select id="select1" onchange="javascript:document.getElementById('hid').value=this.value">后台cmd.CommandText = "INSERT INTO tb(dz,xm,nl) VALUES('"+hid.value+textbox1.Text+"','" + textbox2.Text + "','" + textbox3.Text + "')";
<option>里面的value指定了吗?
如果"select1"是name,并且value有值的话:cmd.CommandText = string.Format("INSERT INTO tb(dz,xm,nl) VALUES('{0}','{1}','{2}')",Request.Form["select1"]+TextBox1.Text,TextBox2.Text,TextBox3.Text);
<select id="Select1" runat="server">
<option>C#</option>
<option>VB</option>
</select> cmd.CommandText = string.Format("INSERT INTO tb(dz,xm,nl) VALUES('{0}','{1}','{2}')",Select1.value+TextBox1.Text,TextBox2.Text,TextBox3.Text);
string text = document.getElementById("select1").options[document.getElementByID("select1").selectedIndex].innerText; // 选中文本 value选中值
document.getElementById("保存值的text").innerText = text;
在后台用代码把值拼起来就行了
String.format(INSERT INTO tb(dz,xm,nl) VALUES ('{0}','{1}','{2})',textbox1.Text.Trim(),textbox2.Text.Trim(),textbox3.Text.Trim());
cmd.CommandText = "INSERT INTO tb(dz,xm,nl) VALUES (@dz , @xm , @nl)";
cmd.Parameters.Add("@dz", SqlDbType.VarChar).Value = textbox1.Text;
cmd.Parameters.Add("@xm", SqlDbType.VarChar).Value = textbox2.Text;
cmd.Parameters.Add("@nl", SqlDbType.VarChar).Value = textbox3.Text;