求高手帮助解决数据库数据插不进的问题
时间:2011-12-09
来源:互联网
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class zc : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string bh = TextBox1.Text;
string mm = TextBox2.Text;
string hh = TextBox3.Text;
string yx = youxiang.Text;
string sex;
string constr = "server=localhost;uid=sa;pwd=111111;database=bh";
SqlConnection con = new SqlConnection(constr);
if(RadioButtonList1.Items[0].Selected)
sex=RadioButtonList1.Items[0].Value;
else
sex=RadioButtonList1.Items[1].Value;
string cmdstr = "insert bh values('" + bh + "','" + mm + "','" + hh + "','" + yx + "','"+ sex +"')";
SqlCommand cmd = new SqlCommand(cmdstr, con);
con.Open();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception err) { Label1.Text = err.Message; }
finally
{
con.Close();Response.Redirect("logion1.aspx");
}
}
}
为什么插不进数据库的表中,请高手指点,多谢多谢!!!!
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class zc : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string bh = TextBox1.Text;
string mm = TextBox2.Text;
string hh = TextBox3.Text;
string yx = youxiang.Text;
string sex;
string constr = "server=localhost;uid=sa;pwd=111111;database=bh";
SqlConnection con = new SqlConnection(constr);
if(RadioButtonList1.Items[0].Selected)
sex=RadioButtonList1.Items[0].Value;
else
sex=RadioButtonList1.Items[1].Value;
string cmdstr = "insert bh values('" + bh + "','" + mm + "','" + hh + "','" + yx + "','"+ sex +"')";
SqlCommand cmd = new SqlCommand(cmdstr, con);
con.Open();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception err) { Label1.Text = err.Message; }
finally
{
con.Close();Response.Redirect("logion1.aspx");
}
}
}
为什么插不进数据库的表中,请高手指点,多谢多谢!!!!
作者: jiangxinping 发布时间: 2011-12-09
string cmdstr = "insert into bh values('" + bh + "','" + mm + "','" + hh + "','" + yx + "','"+ sex +"')";
作者: dalmeeme 发布时间: 2011-12-09
另外
if(RadioButtonList1.Items[0].Selected)
sex=RadioButtonList1.Items[0].Value;
else
sex=RadioButtonList1.Items[1].Value;
其实只要
sex=RadioButtonList1.SelectedValue;
一句就行了。
if(RadioButtonList1.Items[0].Selected)
sex=RadioButtonList1.Items[0].Value;
else
sex=RadioButtonList1.Items[1].Value;
其实只要
sex=RadioButtonList1.SelectedValue;
一句就行了。
作者: dalmeeme 发布时间: 2011-12-09
掉了 into ,规范为:insert into tablename(各列明)values(各列对应的值)
设断点,将SQL语句放到数据库中执行,很快就能找到错误所在。
设断点,将SQL语句放到数据库中执行,很快就能找到错误所在。
作者: woshisadshiwo 发布时间: 2011-12-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28