|
发表于 2020-1-31 21:45:01
|
显示全部楼层
可以啊.
改成vb的就可以了.
SqlConnection conn =null;
SqlDataAdapter dapt = null;
DataSet ds = new DataSet();
string strConnectionString = "Data Source=.;initial catalog=数据库;uid=sa;pwd=xxx";
string strSQL = "SELECT 字段 from 表"
try
{
conn = new SqlConnection(strConnectionString);
conn.Open();
dapt = new SqlDataAdapter(strSQL,conn);
dapt.Fill(ds,"table1");
DataTable dt = ds.Tabls[0];
if(dt.Rows.Count >0)
{
this.Text1.Text = dt.Rows[0]["字段"].ToString();
}
}
catch(System.Exception e)
{
this.Text1.Text = "错误"+e.Message;
}
finally
{
if(conn!=null)
conn.Dispose();
if(dapt!=null)
dapt.Dispose();
}
|
|