【发布时间】:2016-07-17 19:42:06
【问题描述】:
c# asp.net - 将数据插入数据库(不知道 iam 哪里出错了) - 此代码正在执行但根本不工作!我试图通过我创建的网站提供数据,但它根本不会反映在我的数据库中,请帮助!!!!
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
{
SqlConnection con = new SqlConnection("Data Source=GARGI-PC\\ROOT;Initial Catalog=master;Integrated Security=True");
protected void page_load(object sender, EventArgs e)
{}
public void refress()
{
comment1.Text = "";
software1.Checked = true;
hardware1.Checked = false;
both1.Checked = false;
others.Checked = false;
}
protected void btn(object sender, EventArgs e)
{
string type = string.Empty ;
if (hardware1.Checked == true)
{
type = "hardware";
}
if (software1.Checked == true)
{
type = "software";
}
if (both1.Checked == true)
{
type = "both";
}
if (others.Checked == true)
{
type = "others";
}
SqlCommand cmd = new SqlCommand("insert into main_page (type, discription,time) values('" + type + "','" + comment1.Text + "','" + "','"+"now()')", con);
cmd.CommandType = CommandType.Text;
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
refress();
}
catch (Exception ex)
{
}
}
public void btn_clear(object sender, EventArgs e)
{
refress();
}
}
【问题讨论】:
标签: c# mysql sql asp.net database