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

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

于 2022-07-28 发布 文件大小:39.10 kB
0 174
下载积分: 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 个回复

  • 鬼影去验证3389 版本 用户
    鬼影源码去验证码3389 版本 用户 鬼影源码去验证码非常好用的
    2023-02-13 00:05:04下载
    积分:1
  • 程序守护(进程守护)-C#
    程序守护(进程守护)-源代码C# /*  * 由SharpDevelop创建。  * 用户: zhang  * 日期: 2017/3/18  * 时间: 21:50  * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件  */ using System; using System.Diagnostics; using System.Drawing; using System.Threading; using System.Windows.Forms; namespace CPinfoSafe { public sealed class NotificationIcon { private NotifyIcon notifyIcon; private ContextMenu notificationMenu; DialogResult dr; #region Initialize icon and menu public NotificationIcon() { notifyIcon = new NotifyIcon(); notificationMenu = new ContextMenu(InitializeMenu()); notifyIcon.DoubleClick += IconDoubleClick; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotificationIcon)); notifyIcon.Icon = (Icon)resources.Get
    2022-11-01 19:35:03下载
    积分:1
  • C# 使用DrawPolygon方法绘制一个多边形
    C# 调用Graphics对象的DrawPolygon方法绘制一个多边形,我们用代码定义多边形的每条边:Point point6 = new Point(160, 20); //实例化Point类,注意多边形的每个边都需要定义不同数据。   Point[] myPoints ={ point1, point2, point3, point4, point5, point6 };//创建Point结构数组   //调用Graphics对象的DrawPolygon方法绘制一个多边形   ghs.DrawPolygon(myPen, myPoints);
    2022-02-03 12:31:32下载
    积分:1
  • C# 使用字符串数组创建一组单选框数据
    C# 基于字符串数组创建一组单选按钮的例子,附上了例子源代码,大家可了解C#字符串数组的简单应用。   以下是例子中的代码,运行后可见如下图所示的图片效果:   //基于字符串数组创建一组单选按钮   string[] MyArray = new string[4];   MyArray[0] = "渝北区";   MyArray[1] = "巴南区";   MyArray[2] = "长寿区";   MyArray[3] = "南岸区";   RadioButton[] MyRadioButtons =new RadioButton[4];   for (int i = 0; i < 4; ++i)   {    MyRadioButtons[i] = new RadioButton();    MyRadioButtons[i].Text = MyArray[i];    MyRadioButtons[i].Location = new System.Drawing.Point(    10, 20 + i * 20);    this.groupBox1.Controls.Add(MyRadioButtons[i]);   }   this.groupBox1.Text = "请评选全市卫生城区:";
    2022-02-27 00:14:46下载
    积分:1
  • C# TXT 文本文件操作函数集代
    Visual C# TXT 文本文件操作函数集代码,可演示以下功能:在文本中查询包含一组指定单词的句子、查找两个文本文件中的不同句子、查找两个文本文件中的相同句子、在CSV文本文件中计算单列平均值、在CSV文本文件中计算多列平均值、将两个不同文本文件联接成新文件。
    2023-06-02 12:05:03下载
    积分:1
  • C#在JPG图片上添加半透明文字水印
    C#在图片上添加文字,这个仿PhotoShop的功能,用C#可以轻松实现哦,对象为JPG图像,可在上面添加半透明的文字效果,不能可看作是一种图片添加水印的效果,文字是半透明处理了,可隐约看到文字下层的图像细节。   private void Form1_Load(object sender, EventArgs e)   {//在指定图像上添加半透明文字    string MyFileName = "Forest.jpg";    Image MyImage = Image.FromFile(MyFileName);    Graphics g = Graphics.FromImage(MyImage);    String MyText = "国家";    Font MyFont = new Font("宋体", 150);    SolidBrush MyBrush = new SolidBrush(Color.FromArgb(18, 255, 0, 255));    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected;    g.DrawString(MyText, MyFont, MyBrush, 10, 10);    this.pictureBox1.Image = MyImage;   }
    2023-02-17 00:50:03下载
    积分:1
  • C# 判断WPF页面是否运行在浏览器环境下
    C# 判断WPF页面是否运行在浏览器环境下,还可以使用BrowserInteropHelper.Source属性进行深入检测,具体的实现代码如下:   private void Page_Loaded(object sender, RoutedEventArgs e)   {//判断WPF页面是否运行在浏览器环境下    string MyInfo = "";    if (System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted)    {//还可以使用BrowserInteropHelper.Source属性进行深入检测    MyInfo = "当前WPF页面是运行在浏览器环境下!";    }    else    {    MyInfo = "当前WPF页面不是运行在浏览器环境下!";    }    MessageBox.Show(MyInfo, "信息提示", MessageBoxButton.OK);   }
    2022-03-22 08:29:15下载
    积分:1
  • C# 在LINQ to DataSet中对分组操作执行子查询
    C# 在LINQ to DataSet中对分组操作执行子查询,相关代码:   private void button1_Click(object sender, EventArgs e)   {//在LINQ to DataSet中对分组操作执行子查询    SqlConnection MyConnection = new SqlConnection();    MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";    MyConnection.Open();    SqlCommand MyCommand = new SqlCommand("Select * From Orders ", MyConnection);    DataSet MySet = new DataSet();    SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);    MyAdapter.Fill(MySet);    DataTable MyQueryTable = MySet.Tables[0];    var MyQuery = from MyOrder in MyQueryTable.AsEnumerable()    orderby MyOrder.Field("ShipCity")    group MyOrder by MyOrder.Field("ShipCity") into g    select new    {    MyCity = g.Key,    MyMaxFreight = (from MyData in g select MyData.Field("Freight")).Max()   
    2022-01-27 20:20:32下载
    积分:1
  • C# 利用数据对象修改数据
    C# 利用数据对象修改数据,就是简单的修改数据库中的数据,利用数据对象来修改。运行效果如视图所示。本示例代码 中定义了向个C#操作数据库的方法,比如:从数据库中获取指定数据记录、在窗体中显示指定数据记录等。
    2023-05-31 11:00:03下载
    积分:1
  • C# 修改注册表键值禁止修改IE浏览器主页
    C# 通过修改注册表键值的方法实现禁止/允许修改IE浏览器主页,这个方法是通过注册表来修改,通过改变注册表相关键值来打开和关闭某项功能,设置HomePage键值为1,以便禁止修改IE主页,当设置HomePage键值为0,以便允许修改IE主页。主要操作的是注册表的SoftWarePoliciesMicrosoftInternet ExplorerControl Panel键值。
    2022-01-22 04:38:33下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载