登录
首页 » C#源码 » C# 建立SQL Server数据库连接的基本方法

C# 建立SQL Server数据库连接的基本方法

于 2022-07-28 发布 文件大小:39.10 kB
0 140
下载积分: 2 下载次数: 1

代码说明:

C# 建立SQL Server数据库连接的基本方法,核心代码为:   try   {    string ConStr =//创建数据库连接字符串   @"server=WIN-GI7E47AND9RLS;user id=sa;pwd=;database=db_TomeTwo";    SqlConnection con = new SqlConnection(ConStr);//创建数据库连接对象    string SqlStr = "select * from 帐单";//创建SQL查询字符串    SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);//创建数据适配器对象    DataSet ds = new DataSet();//创建数据表    ada.Fill(ds);//填充数据集    this.dgv_Message.DataSource =//设置数据源    ds.Tables[0].DefaultView;   }   catch(Exception ex)//捕获异常   {    MessageBox.Show(ex.Message,"提示!");//弹出消息对话框   }

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 像打字游戏的C#打字练习软件
    像打字游戏的C#打字练习软件,名字叫做“梦雨打字通”。指法练习,出现的字符,在倒计时3秒内会自动消失,若你没有按下键盘上对应的键,则就算打字失败了,这个可以测试你的打字速度,所说里面的大部分分功能借鉴了金山打字通的一些模式。   本软件在编写时,用到了工厂类、随机生产LetterClass、计时器类,每一个Letter在屏幕上的停留时间计时,keyDown事件类,设置 字符总数 正确总数 正确率,X方向的Tick事件等。
    2022-08-04 11:03:56下载
    积分:1
  • C# 读取GDI+图像元数据
    C# 读取GDI+图像元数据,比如可读取图片的长度和宽度/ID/类型等信息.
    2023-04-30 06:00:03下载
    积分:1
  • C# 数据分组统计(单列)
    C# 数据分组统计(单列),这个测试需要连接SQLSERVER才可以,运行效果如上图所示,请下载源码包查看详细代码情况。
    2023-08-05 06:35:03下载
    积分:1
  • C#多个读写文本文件的方法含示例
    C#多个读写文本文件的方法含示例,比如"以文本行为单位写文本文件、以文本行为单位读文本文件、一次性向文本文件写入数据、一次性从文本文件读取数据、一次性向文本文件追加数据。
    2022-05-12 17:08:46下载
    积分:1
  • C# 向StatusBar状态栏控件中添加窗格面板
    C# 向StatusBar状态栏控件中添加窗格面板及文字,也就是把窗口的状态栏分栏,分隔成若干个小区域,显示不同的信息,比如文字提示或图标等。   向StatusBar控件添加窗格面板   StatusBar statusBar1=new StatusBar();   statusBar1.Panels.Add("中华人民共和国");   statusBar1.Panels.Add("重庆市");   statusBar1.Panels.Add("罗斌");   statusBar1.Panels[0].AutoSize = StatusBarPanelAutoSize.Contents;   statusBar1.Panels[1].AutoSize = StatusBarPanelAutoSize.Spring;   statusBar1.Panels[2].AutoSize = StatusBarPanelAutoSize.Contents;   statusBar1.Panels[0].BorderStyle =StatusBarPanelBorderStyle.Raised;   statusBar1.Panels[1].BorderStyle = StatusBarPanelBorderStyle.Sunken;   statusBar1.Panels[2].BorderStyle = StatusBarPanelBorderStyle.Raised;   statusBar1.Panels[2].Icon = new System.Drawing.Icon( @"Error.ico");   statusBar1.ShowPanels = true;   this.Controls.Add(statusBar1);
    2022-05-17 04:53:06下载
    积分:1
  • 7Zip
    This file is part of SevenZipSharp.    SevenZipSharp is free software: you can redistribute it and/or modify    it under the terms of the GNU Lesser General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    SevenZipSharp is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public License    along with SevenZipSharp.  If not, see .
    2022-07-20 00:09:31下载
    积分:1
  • C# DataGridView初级操作范例
    这是一个C# DataGridView初级操作范例,演示了连接数据库、读取数据库、移动数据库指针到下一条、上一条记录的操作,以及将数据绑定到DataGridView控件中显示的整个过程,比较基础级的C#源码,因此希望新手参考:   private void shippersDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)   {//如果错误发生在提交操作过程中,则在 MessageBox 中显示该错误    if (e.Exception != null && e.Context == DataGridViewDataErrorContexts.Commit)    {//测试时在Phone列中输入一个超长的字符串    MessageBox.Show(e.Exception.Message, "信息提示", MessageBoxButtons.OK);    }   }
    2022-01-22 02:28:43下载
    积分:1
  • C# Textbox传值通过Lable显示在窗口上
    C#将Textbox值通过Lable显示在窗口上,演示值的传递,源代码中定义了两个窗口,将值互相传递,最终显示在Lable标签中。当用户点击按钮时,执行以下的代码:   private void button1_Click(object sender, EventArgs e)   {    label2.Text = textBox1.Text;   }
    2022-02-05 07:04:01下载
    积分:1
  • C# 中文简体繁体转换小程序
    Visual C# 简繁体转换,实现中文汉字的简体繁体转换功能,相信这个C#小程序源码会很实用吧,经常用到。编译运行后,请输入要转换的文字,单击对应的按钮,即可实现转换功能,绑定在对应按钮上的代码如下:   C#中文繁体转简体源码:   private void button1_Click(object sender, EventArgs e)   {    string src = txtSrcText.Text.Trim();    byte[] srcByte = Encoding.Default.GetBytes(src);    byte[] desByte = new byte[srcByte.Length];    LCMapString(2052, LCMAP_SIMPLIFIED_CHINESE, srcByte, -1, desByte, srcByte.Length);    string des = Encoding.Default.GetString(desByte);    txtDesText.Text = des;   }   C#中文简体转繁体源码:   private void button2_Click(object sender, EventArgs e)   {    string src = txtSrcText.Text.Trim();    byte[] srcByte = Encoding.Default.GetBytes(src);    byte[] desByte = new byte[srcByte.Length];    LCMapString(2052, LCMAP_TRADITIONAL_CHINESE, srcByte, -1, desByte, srcByte.Length);    string des = Encoding.Default.GetString(desByte);    txtDesText.Text = des;   }
    2022-03-12 07:23:03下载
    积分:1
  • C# 在Vista、Win7中显示XP风格的文件对话框
    C#自定义打开文件对话框,并在文件打开对话框中添加自定义区域,可以在非Windows XP系统中调用XP风格的对话框,比如本例子演示了在Vista或Windows7 中显示XP风格的文件对话框:   private void button1_Click(object sender, EventArgs e)   {//在文件打开对话框中添加自定义区域    this.openFileDialog1.AutoUpgradeEnabled = true;    this.openFileDialog1.CustomPlaces.Add(@"F:");    this.openFileDialog1.ShowDialog();   }   private void button2_Click(object sender, EventArgs e)   {//在Vista中显示XP风格的文件对话框    this.openFileDialog1.AutoUpgradeEnabled = false;    this.openFileDialog1.ShowDialog();   }
    2022-03-15 22:57:57下载
    积分:1
  • 696516资源总数
  • 106409会员总数
  • 8今日下载