如何读取sql表中的字段的内容填到edit.text
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private SqlConnection conn;
private string strConn, strSQL;
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
strConn = "server=(local);database=spms_54;uid=sa;pwd=;";
conn = new SqlConnection(strConn);
conn.Open();
try
{
strSQL = "select usercode,userpassword,grade from tuser";
SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds);
dt = ds.Tables[0];
edit.text = dt.rows[0]["UserCode"].toString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private SqlConnection conn;
private string strConn, strSQL;
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
strConn = "server=(local);database=spms_54;uid=sa;pwd=;";
conn = new SqlConnection(strConn);
conn.Open();
try
{
strSQL = "select usercode,userpassword,grade from tuser";
SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds);
dt = ds.Tables[0];
edit.text = dt.rows[0]["UserCode"].toString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询