在window form中如何连sql server数据库,谢谢

jjyzhw111 2003-08-21 03:05:53
在window form中如何连sql server数据库,谢谢
...全文
78 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jjyzhw111 2003-08-21
  • 打赏
  • 举报
回复
thanks a lot of
dahuzizyd 2003-08-21
  • 打赏
  • 举报
回复
string strSql = "select department.* from department";

string strConn ="data source=YL5;initial catalog=Address;workstation id=YL5;packet size=4096";

SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd_dep = new SqlCommand(strSql,conn);
SqlDataAdapter adp_dep = new SqlDataAdapter();

adp_dep.SelectCommand = cmd_dep;
DataSet ds = new DataSet();

conn.Open();
adp_dep.Fill(ds);
建议你还是先看看帮助:
Visual Basic 和Visual C# --访问数据--数据演练
yanyunpaladin 2003-08-21
  • 打赏
  • 举报
回复
sdk里类库的例程多得就是,看看就行了^_^
system.data.xxx随便看一个就行了
zhehui 2003-08-21
  • 打赏
  • 举报
回复
string sqltxt="Persist Security Info=False;User ID=sa;Initial Catalog=zhongtian;Data Source=ytf;Password=xu;";
SqlConnection sqlcon=new SqlConnection(sqltxt);
try
{
sqlcon.Open();
SqlCommand sqlcm=new SqlCommand("select Max(product_id) from product_class where product_id like '"+e1+"__'",sqlcon);
SqlDataReader dr=sqlcm.ExecuteReader();
if(dr.Read())
{
if(e1.Length==4)
{
textBox1.Text=Int32.Parse(dr.GetValue(0).ToString().Substring(4));
}
//else
//{
// textBox1.Text=dr.GetValue(0).ToString().Substring(6);
//}
//textBox1.Text=dr.GetValue(0).ToString();
sqlcon.Close();
}
}
catch(System.Data.SqlClient.SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlcon.Close();
}

}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧