using (SqlConnection conn = new SqlConnection("server=(SQL服务器名称);user id=sa;password=(SQL密码);database=连接的数据库"))
{
string sql = "select * from mess where stu_name=@a,@b,@c,@d,@e";
SqlCommand com = new SqlCommand(sql,conn);
com.Parameters.AddWithValue("@name", textBox1.Text);
com.Parameters.AddWithValue("@name", textBox2.Text);
com.Parameters.AddWithValue("@name", textBox3.Text);
com.Parameters.AddWithValue("@name", textBox4.Text);
com.Parameters.AddWithValue("@name", textBox5.Text);
conn.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
textBox1.Text = dr["第一列的列名"].ToString();
textBox2.Text = dr["第二列的列名"].ToString();
textBox3.Text = dr["第三列的列名"].ToString();
textBox4.Text = dr["第思列的列名"].ToString();
textBox5.Text = dr["第五列的列名"].ToString();
}
修改
}
}
string sql = "update mess set 第一列的列名=@a,第二列的列名=@b,第三列的列名=@c,第四列的列名=@d,第五列的列名=@e";
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
com.Parameters.AddWithValue("@a", textBox1.Text);
com.Parameters.AddWithValue("@b", textBox2.Text);
com.Parameters.AddWithValue("@c", textBox3.Text);
com.Parameters.AddWithValue("@d", textBox4.Text);
com.Parameters.AddWithValue("@e", textBox5.Text);
com.ExecuteNonQuery();
MessageBox.Show("修改成功");
}
}
}



