小编use*_*370的帖子

使用sql连接的最佳/标准方法是什么?

protected void populateDataGrid()
{
    string connectionString = configurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
    string command = "select * from student";

    SqlDataAdapter dataAdapter = new SqlDataAdapter(command, connectionString);
    DataSet data = new DataSet();

    dataAdapter.Fill(data);
    GridView1.DataSource = data;
    GridView1.DataBind();
}

protected void Button2_Click(object sender, EventArgs e)
{
    string connectionString = ConfigurationManager.ConnectionStrings["sqlstudentConnectionString"].ConnectionString;
    string command = @"INSERT INTO [student] (studentID, studentFirstName, studentLastName) 
                       VALUES (" + TextID.Text + ", '" + TextFirstName.Text + "', '" + TextLastName.Text + "')";
    SqlConnection sqlConnection = new SqlConnection(connectionString);

    SqlCommand cmd = new SqlCommand();
    cmd.CommandType = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net sqlconnection

2
推荐指数
1
解决办法
141
查看次数

标签 统计

asp.net ×1

c# ×1

sqlconnection ×1