0

我尝试了很多类型,我不知道如何插入。

sql server 有问题吗?

请快点帮我..

SqlConnection con = new SqlConnection( "Data Source=localhost/SQLEXPRESS.Polaris.dbo;Initial Catalog=Polaris;Integrated Security=True;Pooling=False");

protected void Page_Load(object sender, EventArgs e)
{
        con.Open();
}

protected void Button3_Click(object sender, EventArgs e)
{
    con.Open();

    SqlDataReader rdr = null;
    //string s1 = "insert into Login values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.SelectedItem.Value + "'";
    SqlCommand cmd1 = new SqlCommand("insert into Login values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.SelectedItem.Value + "'");
    cmd1.Connection = con;
    rdr = cmd1.ExecuteReader();
    Label2.Visible = true;
    //EndEventHandler.RemoveAll();
 }

 protected void Button2_Click(object sender, EventArgs e)
 {
        Response.Redirect("WebForm1.aspx");
 }
4

2 回答 2

1

无法将类型“WebApplication4.SqlConnection”隐式转换为“System.Data.SqlClient.SqlConnection”

根据错误,您在 WebApplication4 命名空间中有名为 SqlConnection 的类。您可能错误地生成了该类。您需要先删除该类,然后添加对 System.Data.SqlClient

于 2013-04-21T19:14:19.283 回答
0

以下是您可以执行的操作:

SqlConnection con = new SqlConnection( "Data Source=localhost/SQLEXPRESS.Polaris.dbo;Initial Catalog=Polaris;Integrated Security=True;Pooling=False");
protected void Button3_Click(object sender, EventArgs e)
{
    con.Open();
    string s1 = "insert into Login values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.SelectedItem.Value + "'";
    SqlCommand cmd = new SqlCommand(s1, con);
    cmd.ExecuteNonQuery();
}
于 2013-04-21T18:44:34.793 回答