【发布时间】:2015-12-12 02:37:11
【问题描述】:
我需要使用 txtbox 和按钮 (btnAdd) 将内容添加到我的数据库 这是我的代码,但是 CommandType.Text;部分有错误,我无法修复它。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace _21542890_F
{
public partial class Add_Product : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Dylan\Documents\Company.mdf;Integrated Security=True;Connect Timeout=30");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lbtnHome_Click(object sender, EventArgs e)
{
Response.Redirect("Home Page.aspx");
}
protected void btnAdd_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Company values('"+txtProductName.Text+"','"+txtProductPrice.Text+"')";
cmd.ExecuteNonQuery();
con.Close();
}
}
}
【问题讨论】:
-
请发布您的构建/运行时错误
-
发布
Company表的架构。
标签: c# mysql asp.net sqlconnection sqlcommand