SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=.;DataBase=Sport;Uid=sa;Pwd=123";
string strSql;
strSql = "Selecte Ath_Name Into #txtName3.Text From Athlete Where Ath_Num ='"+ txtNumber3.Text+"'";
SqlCommand cmd = new SqlCommand(strSql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();我这么有什么错误?
conn.ConnectionString = "Server=.;DataBase=Sport;Uid=sa;Pwd=123";
string strSql;
strSql = "Selecte Ath_Name Into #txtName3.Text From Athlete Where Ath_Num ='"+ txtNumber3.Text+"'";
SqlCommand cmd = new SqlCommand(strSql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);懂了么?
后台数据<--->DataContext<--->UI 任何一个前台操作不要写sql语句,否则等于垃圾代码,无法维护。。
ExecuteNonQuery用于更新,删除,添加删除操作,你这里是查询,肯定是不对的,而且大兄弟,2楼大佬说的对啊,你这select都能写错,这手动代码编写能力太恐怖了
conn.ConnectionString = "Server=.;DataBase=Sport;Uid=sa;Pwd=123";
string strSql;
strSql = "Select Ath_Name From Athlete Where Ath_Num ='" + txtNumber3.Text + "'";
SqlCommand cmd = new SqlCommand(strSql, conn);
conn.Open();
object obj = cmd.ExecuteScalar();
txtNumber3.Text = obj.ToString();
conn.Close();
2.ExecuteNonQuery,你还获取什么去?
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=.;DataBase=Sport;Uid=sa;Pwd=123";
string strSql;
strSql = "Select Ath_Name Into #txtName3.Text From Athlete Where Ath_Num ='"+ txtNumber3.Text+"'";
SqlCommand cmd = new SqlCommand(strSql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);懂了么?ExecuteNonQuery用于更新,删除,添加删除操作,你这里是查询,肯定是不对的,而且大兄弟,2楼大佬说的对啊,你这select都能写错,这手动代码编写能力太恐怖了
这是一个插入语句 select into 后面是表名,他可以提取出数据