[WebMethod]
public string cx(string x)
{
string s=null ;
string str = "Data Source=localhost;Initial Catalog=英语语法;Persist Security Info=true;User ID=sa;Password=123";
SqlConnection con = new SqlConnection(str);
string comStr = "select 内容 from 语法 where 类别='x'";
con.Open();
//public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
//}*/
SqlCommand com = new SqlCommand(comStr, con);
SqlDataReader rd = com.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{ s = rd["内容"].ToString();
}
}
rd.Close();
con.Close();
return s; }
}
public string cx(string x)
{
string s=null ;
string str = "Data Source=localhost;Initial Catalog=英语语法;Persist Security Info=true;User ID=sa;Password=123";
SqlConnection con = new SqlConnection(str);
string comStr = "select 内容 from 语法 where 类别='x'";
con.Open();
//public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
//}*/
SqlCommand com = new SqlCommand(comStr, con);
SqlDataReader rd = com.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{ s = rd["内容"].ToString();
}
}
rd.Close();
con.Close();
return s; }
}
然后DataRow row=ds.Tables[0].Rows[0];这样第一行就赋给了row变量啦
<string xmlns="http://tempuri.org/">select 内容 from 语法 where 类别='x'</string>
<string xmlns="http://tempuri.org/">select 内容 from 语法 where 类别='x'</string>
为什么数据库,表,字段都是中文啊,这样不好吧。觉得还是要规范些,不用中文做字段之类的。
<string xmlns="http://tempuri.org/">string</string> string 就是你查询出的数据