C#关于插入后台数据库的问题
来源:百度知道 编辑:UC知道 时间:2024/05/26 06:15:27
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected SqlConnection myconn = new SqlConnection();
protected SqlCommand mycomm = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
myconn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["sqlconn"];
}
protected void Button1_Click(object sender, EventArgs e)
{
myconn.Open();
string query = "select count(*) from employee where employeeid='" + TextBox1.Text + "'";
mycomm = new SqlCommand(qu
catch (Exception ex)
{
Response.Write("错误:<br/>" + ex.Message);
Response.End();
}
看看错误是什么
try 的下面加一句"mycomm.CommandText.Clear();",即:
try
{
mycomm.CommandText.Clear();
mycomm.CommandText = "insert into employee
..............
试试
你这里TRY的位置应该放到最前面好点,虽然放到你那也没错误,但如果前面有异常就捕捉不到了!
看见这么长的代码头昏,你把错误贴出来啊!错误有很多种呢!
protected SqlConnection myconn = new SqlConnection();
protected SqlCommand mycomm = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
myconn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["sqlconn"];
}
改成
protected SqlConnection myconn = new SqlConnection();
protected SqlCommand mycomm = new SqlCommand();
myconn.ConnectionString = System.Configuration.ConfigurationManager.AppSet