[quote=引用 6 楼 qq_37753824 的回复:] string connectionstring="*********"; string SQLstring="select top 1 name,price from TableName"; using(SqlConnection connection=new SqlConnection(connectionstring)) { DataSet ds=new DataSet(); try { connection.Open(); SqlDataAdapter da=new SqlDataAdapter(SQLstring,connection); da.Fill(ds,"ds"); connection.Close(); if(ds.Rows.Count>0) { button1.Text=ds.Row[0]["name"].ToString()+" "+ds.Row[0]["price"].ToString(); } } catch (System.Data.SqlClient.SqlException ex) { throw new Exception(ex.Message); } }
string connectionstring="*********"; string SQLstring="select top 1 name,price from TableName"; using(SqlConnection connection=new SqlConnection(connectionstring)) { DataSet ds=new DataSet(); try { connection.Open(); SqlDataAdapter da=new SqlDataAdapter(SQLstring,connection); da.Fill(ds,"ds"); connection.Close(); if(ds.Rows.Count>0) { button1.Text=ds.Row[0]["name"].ToString()+" "+ds.Row[0]["price"].ToString(); } } catch (System.Data.SqlClient.SqlException ex) { throw new Exception(ex.Message); } }
你是赋值不会 还是获取数据不会?
110,552
社区成员
642,562
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧