【发布时间】:2016-10-18 09:26:14
【问题描述】:
我的表单没有将 Texbox 中的文本保存到数据库中。我的 .cs 代码文件可能有问题,但我无法解决。
这很可能是我的连接字符串。
我的网络表单:
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Enter selection text:
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<td colspan="2" align="center">
<asp:Button ID="Button1" runat="server" Text="Submit" />
</td>
</tr>
</table>
</div>
</form>
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=db65225900.db.1and1.com; Initial Catalog=db211255182; User ID=dbo652259000; Password=Password");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into homepageSelection values('"+TextBox1.Text+"')";
cmd.ExecuteNonQuery();
con.Close();
}
}
我的 MsSQL 设置如下:
1 列:selectionText nvarchar(3000)
【问题讨论】:
-
您的插入查询错误
-
如果表只包含一列就可以了
-
你有什么错误吗?
-
调试时有没有收到任何错误信息?插入语句应该是这样的:
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9); -
你得到什么错误?
标签: c# sql asp.net database forms