private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\SQLEXPRESS");
conn.Open();
DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[0]["math"].ToString();
this.textBox2.Text = dt.Rows[0]["age"].ToString();
this.textBox3.Text = dt.Rows[0]["course"].ToString();
conn.Close();
}
远程连接已打开,Server填IP也不行,能不能给个代码,大谢!
{
SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\SQLEXPRESS");
conn.Open();
DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[0]["math"].ToString();
this.textBox2.Text = dt.Rows[0]["age"].ToString();
this.textBox3.Text = dt.Rows[0]["course"].ToString();
conn.Close();
}
远程连接已打开,Server填IP也不行,能不能给个代码,大谢!
解决方案 »
- C#中加入Access登陆(求指教)
- 有哪位高手帮忙给我写个测试类?谢谢!
- 如何设置DataGridView最左列的标题
- winform中datagridview列的显示问题~~~
- 点击右上角”关闭“,程序并不关闭,进入托盘区,并且不显示在状态区,怎么实现?
- 如何取得IP地址(在线等哦)
- foreach循环有点不懂什么意思。求个好心人帮我讲解一下
- 我用c#打开excel以后,要写入大量数据,但是在这过程中打开excel会打开正在写的excel.
- Mongodb NOSql 数据库问题,是否可以插入带接口的类
- winform 中datagrid控件有没有 恢复和撤销
- 如何获取当前控件获取焦点前的,上一个焦点控件对象?
- Math.Round(-3.40282346639E+038, 2) 怎么不凑效呢?
顺便检查你的da(DataAdapter)是否初始化了。
用DataSet实现更简单,有关Ds和Dt的关系和用法,参看这里:http://qing.94nn.com/article.asp?id=118
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM tablename";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[0]["math"].ToString();
this.textBox2.Text = dt.Rows[0]["age"].ToString();
this.textBox3.Text = dt.Rows[0]["course"].ToString();
conn.Close();
{
SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\SQLEXPRESS");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Student";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[0]["math"].ToString();
this.textBox2.Text = dt.Rows[0]["age"].ToString();
this.textBox3.Text = dt.Rows[0]["course"].ToString();
conn.Close();
}
还是连不上