数据插入执行中出现了异常,请检查数据库或数据库连接 请问怎么解决???
作做一个插入学生信息的系统代码如下usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.L...
作做一个插入学生信息的系统代码如下
using System;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
return;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = this.txtname.Text;//学生姓名
string sex = this.txtsex.Text;//学生性别
string old = this.txtold.Text;;//学生年龄
string hight = this.txthight.Text;;//学生身高
string weight = this.txtweight.Text;;//学生体重
string sql = string.Format("INSERT INTO Table1 ( name='" + name + " ', sex='" + sex + " ',old='" + old + " ',hight='" + hight + " ',weight='" + weight+")");
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
int result = 0;
try
{
con.Open();
//执行插入SQL语句
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
if (result == 1)
{
this.Response.Write("<script type='text/javascript' language='javascript'>alert('数据插入成功,请查看数据')</script> ");
}
else
{
this.Response.Write("<script type='text/javascript' language='javascript'>alert('数据插入执行中出现了异常,请检查数据库或数据库连接')</script> ");
}
}
}
错了,是这里出错:
string name = this.txtname.Text;//学生姓名
string sex = this.txtsex.Text;//学生性别
string old = this.txtold.Text;;//学生年龄
string hight = this.txthight.Text;;//学生身高
string weight = this.txtweight.Text;;//学生体重
string sql = string.Format("INSERT INTO Table1 ( name='" + name + " ', sex='" + sex + " ',old='" + old + " ',hight='" + hight + " ',weight='" + weight+")");
com.parameters.add("@EmpName",sqltype.varchar,20).value=this.txtweight.Text;;//学生体重 展开
using System;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
return;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = this.txtname.Text;//学生姓名
string sex = this.txtsex.Text;//学生性别
string old = this.txtold.Text;;//学生年龄
string hight = this.txthight.Text;;//学生身高
string weight = this.txtweight.Text;;//学生体重
string sql = string.Format("INSERT INTO Table1 ( name='" + name + " ', sex='" + sex + " ',old='" + old + " ',hight='" + hight + " ',weight='" + weight+")");
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
int result = 0;
try
{
con.Open();
//执行插入SQL语句
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
if (result == 1)
{
this.Response.Write("<script type='text/javascript' language='javascript'>alert('数据插入成功,请查看数据')</script> ");
}
else
{
this.Response.Write("<script type='text/javascript' language='javascript'>alert('数据插入执行中出现了异常,请检查数据库或数据库连接')</script> ");
}
}
}
错了,是这里出错:
string name = this.txtname.Text;//学生姓名
string sex = this.txtsex.Text;//学生性别
string old = this.txtold.Text;;//学生年龄
string hight = this.txthight.Text;;//学生身高
string weight = this.txtweight.Text;;//学生体重
string sql = string.Format("INSERT INTO Table1 ( name='" + name + " ', sex='" + sex + " ',old='" + old + " ',hight='" + hight + " ',weight='" + weight+")");
com.parameters.add("@EmpName",sqltype.varchar,20).value=this.txtweight.Text;;//学生体重 展开
2个回答
2012-03-21
展开全部
看下详细错误日志吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询