我用SqlDataSource连接的数据库
想要实现用textbox插入数据库 为什么可以执行但是数据插入不进去   
button代码和 SqlDataSource事件如下
求大神指点using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default6 : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {  }
  protected void Button1_Click(object sender, EventArgs e)
  {
      }
  protected void Button2_Click(object sender, EventArgs e)
  {
  SqlDataSource1.Select(DataSourceSelectArguments.Empty);
  }
  protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
  {  string insert = "insert into User_Info (UserName) values ('" + TextBox2.Text + "')";
  }
}
  本人刚开始学习ASP 代码请写详细一点 谢谢

解决方案 »

  1.   

    断点一下 或者是点击按钮刷新了 txt又为空了
      

  2.   

    您不结贴吗?恐怕这个是没有人来给你帮忙的根源
    "insert into User_Info(UserName) values('" + TextBox2.Text + "')" 语句格式化
      

  3.   

    asp:SqlDataSource ID="ManageProductsDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
           InsertCommand=
            "INSERT INTO [Products] ([ProductName], [UnitPrice], [Discontinued])
             VALUES (@ProductName, @UnitPrice, @Discontinued)">
        <InsertParameters>
            <asp:Parameter Name="ProductName" Type="String" />
            <asp:Parameter Name="UnitPrice" Type="Decimal" />
            <asp:Parameter Name="Discontinued" Type="Boolean" />
        </InsertParameters>
    </asp:SqlDataSource>直接这样多好
    http://msdn.microsoft.com/zh-cn/dd262233 使用SqlDataSource 插入、