c#lc 连接mysql数据库数据库

C#修改和删除数据库记录的实现方法 - 乐博网
&|&&|&&|&&|&&|&&|&&|&&|&&|&&|&
最新公告:
&&没有公告
您现在的位置:&&>>&&>>&技术文摘正文
C#修改和删除数据库记录的实现方法
C#修改和删除数据库记录的实现方法
作者:佚名&&&
来源:乐博网收集 &&&
更新时间:
C#修改和删除数据库记录的实现方法
一.程序设计和运行的环境设置:(1).视窗2000服务器版(2).Microsoft Access Data Component 2.6 以上版本 ( MADC 2.6 )(3).本文程序使用的数据库的介绍:为了方便起见,在选用数据库方面选用了本地数据库Access 2000,当然你也可以选用其他类型的数据库,只需要更改文章后面的程序源代码中数据库的引擎,并更改对应的代码就可以了。本程序中使用的数据库名称为sample.mdb,在此数据库中有一张数据表books。此数据表的结构如下:
bookauthor
书架号二.程序设计难点和应该注意的问题:在程序设计中的重点和难点就是如何用Visual C#删除记录和如何修改记录。下面就这二个问题进行必要的论述:(1).如何用Visual C#正确删除数据表中的记录:在用Visual C#删除记录的时候要注意的是:必须从二个方面彻底删除记录,即从数据库和用Visual C#编程时产生的一个DataSet对象中彻底删除。在程序设计的时候,如果只是删除了DataSet对象中的记录信息,这种删除是一种伪删除。这是因为当他退出程序,又重新运行程序,会发现,那个要删除的记录依然还存在。这是因为DataSet对象只是对数据表的一个镜像,并不是真正的记录本身。但如果只是从数据库中删除记录,因为我们此时程序用到的数据集合是从DataSet对象中读取的,子DataSet对象中依然保存此条记录的镜像。所以就会发现,我们根本没有删除掉记录,但实际上已经删除了。此时只有退出程序,重新运行,才会发现记录已经删除了。本文使用的方法是删除以上二个方面的记录或记录镜像信息。当然你也可以使用其他的方法,譬如:首先从数据库中删除记录,然后重新建立数据连接,重新创建一个新的DataSet对象。这种方法虽然也可以达到相同目的,但显然相对繁杂些,所以本文采用的是第一种方法--直接删除。在程序中具体的实现语句如下:
//连接到一个数据库string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;OleDbConnection myConn = new OleDbConnection ( strCon ) ;myConn.Open ( ) ;string strDele = "DELETE FROM books WHERE bookid= " + t_bookid.TOleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;//从数据库中删除指定记录myCommand.ExecuteNonQuery ( ) ;//从DataSet中删除指定记录信息myDataSet.Tables [ "books" ] . Rows [ myBind.Position ] . Delete ( ) ;myDataSet.Tables [ "books" ] . AcceptChanges ( ) ;myConn.Close ( ) ;(2).用Visual C#来修改数据表中的记录:在用Visual C#修改记录和删除记录,在程序设计中大致差不多,具体的实现方式也是通过SQL语句调用来实现的。下面就是在程序中修改记录的具体语句://连接到一个数据库string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;OleDbConnection myConn = new OleDbConnection ( strCon ) ;myConn.Open ( ) ;//从数据库中修改指定记录string strUpdt = " UPDATE books SET booktitle = '"+ t_booktitle.Text + "' , bookauthor = '"+ t_bookauthor.Text + "' , bookprice = "+ t_bookprice.Text + " , bookstock = "+ t_bookstock.Text + " WHERE bookid = " + t_bookid.TOleDbCommand myCommand = new OleDbCommand ( strUpdt , myConn ) ;myCommand.ExecuteNonQuery ( ) ;myConn.Close ( ) ;(3).在了解了如何用Visual C#删除和修改记录以后,结合《Visual C#中轻松浏览数据库记录》文的内容,就可以得到用Visual C#完成删除和修改数据记录的比较完整程序代码,以下是本文中介绍程序的运行后的程序界面:点击小图放大,本文中程序运行后的界面三.用Visual C#实现删除和修改数据库记录的完整源程序代码:
using Susing System.DponentMusing System.Windows.Fusing System.Data.OleDusing System.Dpublic class DataEdit : Form { ponentModel.Cprivate Bprivate Bprivate Bprivate Bprivate Bprivate Bprivate TextBox t_private TextBox t_private TextBox t_private TextBox t_private TextBox t_private Label l_private Label l_private Label l_private Label l_private Label l_private Label label1 ;private System.Data.DataSet myDataSprivate BindingManagerBase myBprivate bool isBound =//定义此变量,是判断组件是否已经绑定数据表中的字段public DataEdit ( ) {// 对窗体中所需要的内容进行初始化InitializeComponent ( ) ;//连接到一个数据库GetConnected ( ) ;}//清除程序中用到的所有资源public override void Dispose ( ) {base.Dispose ( ) ;components.Dispose ( ) ;}public void GetConnected ( ){try{//创建一个 OleDbConnection对象string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;OleDbConnection myConn = new OleDbConnection ( strCon ) ;string strCom = " SELECT * FROM books " ;//创建一个 DataSet对象myDataSet = new DataSet ( ) ;myConn.Open ( ) ;OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;myCommand.Fill ( myDataSet , "books" ) ;myConn.Close ( ) ;//判断数据字段是否绑定到 TextBoxesif ( !isBound ){//以下是为显示数据记录而把数据表的某个字段绑定在不同的绑定到文本框"Text"属性上t_bookid.DataBindings.Add ( "Text" , myDataSet , "books.bookid" ) ;t_booktitle.DataBindings.Add ( "Text" , myDataSet , "books.booktitle" ) ;t_bookauthor.DataBindings.Add ( "Text" , myDataSet , "books.bookauthor" ) ;t_bookprice.DataBindings.Add ( "Text" , myDataSet , "books.bookprice" ) ;t_bookstock.DataBindings.Add ( "Text" , myDataSet , "books.bookstock" ) ;//设定 BindingManagerBase//把对象DataSet和"books"数据表绑定到此myBind对象myBind = this.BindingContext [ myDataSet , "books" ] ;isBound =}}catch ( Exception e ){MessageBox.Show ( "连接数据库发生错误为:" + e.ToString ( ) , "错误!" ) ;}}public static void Main ( ) {Application.Run ( new DataEdit ( ) ) ;}private void InitializeComponent ( ){<ponents = ponentModel.Container ( ) ;this.t_bookid = new TextBox ( ) ;this.previousrec = new Button ( ) ;this.l_bookauthor = new Label ( ) ;this.delete = new Button ( ) ;this.t_booktitle = new TextBox ( ) ;this.t_bookauthor = new TextBox ( ) ;this.t_bookprice = new TextBox ( ) ;this.l_bookprice = new Label ( ) ;this.t_bookstock = new TextBox ( ) ;this.l_bookstock = new Label ( ) ;this.l_booktitle = new Label ( ) ;this.update = new Button ( ) ;this.nextrec = new Button ( ) ;this.lastrec = new Button ( ) ;this.firstrec = new Button ( ) ;this.label1 = new Label ( ) ;this.l_bookid = new Label ( ) ;t_bookid.Location = new System.Drawing.Point ( 184 , 56 ) ;t_bookid.Size = new System.Drawing.Size ( 80 , 20 ) ;t_booktitle.Location = new System.Drawing.Point ( 184 , 108 ) ;t_booktitle.Size = new System.Drawing.Size ( 176 , 20 ) ;t_bookauthor.Location = new System.Drawing.Point ( 184 , 160 ) ;t_bookauthor.Size = new System.Drawing.Size ( 128 , 20 ) ;t_bookprice.Location = new System.Drawing.Point ( 184 , 212 ) ;t_bookprice.Size = new System.Drawing.Size ( 80 , 20 ) ;t_bookstock.Location = new System.Drawing.Point ( 184 , 264 ) ;t_bookstock.Size = new System.Drawing.Size ( 80 , 20 ) ;
上一篇: 下一篇:
【字体: 】【】【】
  相关文章:(只显示最新16条)
乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!联系邮箱:Shiny# (#替换为@)用VisualC#中轻松浏览数据库记录
ZDNet软件频道 时间: 作者:中国IT实验室 | 中国IT实验室 
本文关键词:
用Delphi或者VB编程,在对数据库中的记录进行操作的时候,经常用到一个名称为数据导航器的组件,通过这个组件,可以非常方便的实现对已经绑定到此组件的数据表中的记录进行浏览。就是所谓的上一条记录、下一条记录、首记录、尾记录等。
  &&& 用Delphi或者VB,在对数据库中的记录进行操作的时候,经常用到一个名称为数据导航器的组件,通过这个组件,可以非常方便的实现对已经绑定到此组件的数据表中的记录进行浏览。就是所谓的上一条记录、下一条记录、首记录、尾记录等。那么在 是否也存在这样的组件呢?答案是否定的。但由于 有着强大的数据库处理能力,所以可以比较方便的做一个类似于此组件的程序。本文就是来介绍此程序的具体制作过程。
&&& 一、 程序的主要功能介绍:
&&& 程序打开本地Acess数据库(sample.mdb)中的book数据表,然后把book数据表中的字段绑定到程序提供的文本框中,显示出来。通过程序中的四个按钮"首记录"、"尾记录"、"上一条"、"下一条",实现对book数据表中的记录浏览。程序的运行界面如下:
&&& 二、程序设计和运行的环境设置:
&&& (1)视窗2000服务器版
&&& (2)Microsoft Acess Data Component 2.6 ( MADC 2.6 )
&&& 三、程序设计难点和应该注意的问题:
&&& (1)如何实现把数据表中的字段用文本框来显示:
&&& 如果直接把字段的值赋值给文本框,这时如果用"下一条"等按钮来浏览数据记录的时候,文本框的值是不会变化的。如何让文本框根据数据表中的记录指针来动态的显示要字段值,这是本文的一个重点,也是一个难点。
&&& 本文是通过把数据表中的字段值绑定到文本框的"Text"属性上,来实现动态显示字段数值的。实现这种处理要用到文本框的DataBindings属性和其中的Add方法。具体语法如下:
&&& 文本组件名称.DataBindings.Add ( "Text" , DataSet对象 , 数据表和字段名称 ) ;
&&& 在程序具体如下:
t_bookid.DataBindings.Add ( "Text" , myDataSet , "books.bookid" ) ;
这样就可以根据记录指针来实现要显示的字段值了。
&&& (2)如何改变记录指针:
&&& 只有掌握如何改变记录指针,才可以随心所欲的浏览记录。 改变记录指针是通过一个命叫BindingManagerBase对象来实现的。此对象封装在名称空间System.Windows.Froms中。BindingManagerBase对象是一个抽象的对象,管理所有绑定的同类的数据源和数据成员。在程序设计中主要用到BindingManagerBase对象中的二个属性,即:Position属性和Count属性。第一个属性是记录了数据集的当前指针,后一个属性是当前数据集中的记录总数。由此可以得到改变记录指针的四个按钮对应的程序代码:
i&.首记录:myBind.Position = 0 ;ii&.尾记录:myBind.Position = myBind.Count - 1 ;iii&.下一条记录和操作后运行界面:if ( myBind.Position == myBind.Count -1 )MessageBox.Show ( "已经到了最后一条记录!" ) ;elsemyBind.Position += 1 ;
iV&.上一条记录和操作后运行界面:if ( myBind.Position == 0 )MessageBox.Show ( "已经到了第一条记录!" ) ;elsemyBind.Position -= 1 ;
&&& 四.程序源代码:
using Susing System.DponentMusing System.Windows.Fusing System.Data.OleDusing System.D
public class DataView : Form {ponentModel.Cprivate Bprivate Bprivate Bprivate Bprivate TextBox t_private TextBox t_private TextBox t_
private TextBox t_private TextBox t_private Label l_private Label l_private Label l_private Label l_private Label l_private Label label1 ;private System.Data.DataSet myDataSprivate BindingManagerBase myB
public DataView ( ){//连接到一个数据库GetConnected ( ) ;// 对窗体中所需要的内容进行初始化InitializeComponent ( );}public override void Dispose ( ) {base.Dispose ( ) ;components.Dispose ( ) ;}public static void Main ( ) {Application.Run ( new DataView ( ) ) ;}public void GetConnected ( ){try{//创建一个 OleDbConnectionstring strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb" ;OleDbConnection myConn = new OleDbConnection ( strCon ) ;string strCom = " SELECT * FROM books " ;//创建一个 DataSetmyDataSet = new DataSet ( ) ;
myConn.Open ( ) ;//用 OleDbDataAdapter 得到一个数据集OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;//把Dataset绑定books数据表myCommand.Fill ( myDataSet , "books" ) ;//关闭此OleDbConnectionmyConn.Close ( ) ;}catch ( Exception e ){MessageBox.Show ( "连接错误! " + e.ToString ( ) , "错误" ) ;}}private void InitializeComponent ( ){<ponents = ponentModel.Container ( ) ;this.t_bookid = new TextBox ( ) ;this.nextrec = new Button ( ) ;
this.lastrec = new Button ( ) ;this.l_bookid = new Label ( ) ;this.t_books = new TextBox ( ) ;this.t_booktitle = new TextBox ( ) ;this.t_bookprice = new TextBox ( ) ;this.firstrec = new Button ( ) ;this.l_booktitle = new Label ( ) ;this.l_bookprice = new Label ( ) ;this.l_books = new Label ( ) ;this.previousrec = new Button ( ) ;this.l_bookauthor = new Label ( ) ;this.t_bookauthor = new TextBox ( ) ;this.label1 = new Label ( ) ;
//以下是对数据浏览的四个按钮进行初始化firstrec.Location = new System.Drawing.Point ( 55 , 312 ) ;firstrec.ForeColor = System.Drawing.Color.Bfirstrec.Size = new System.Drawing.Size ( 40 , 24 ) ;firstrec.TabIndex = 5 ;firstrec.Font = new System.Drawing.Font("仿宋", 8f );firstrec.Text = "首记录";firstrec.Click += new System.EventHandler(GoFirst);previousrec.Location = new System.Drawing.Point ( 125 , 312 ) ;previousrec.ForeColor = System.Drawing.Color.Bpreviousrec.Size = new System.Drawing.Size(40, 24) ;previousrec.TabIndex = 6 ;previousrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;previousrec.Text = "上一条" ;previousrec.Click += new System.EventHandler ( GoPrevious ) ;nextrec.Location = new System.Drawing.Point ( 195 , 312 );nextrec.ForeColor = System.Drawing.Color.Bnextrec.Size = new System.Drawing.Size ( 40 , 24 ) ;nextrec.TabIndex = 7 ;nextrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;nextrec.Text = "下一条" ;nextrec.Click += new System.EventHandler ( GoNext );
lastrec.Location = new System.Drawing.Point ( 265 , 312 ) ;lastrec.ForeColor = System.Drawing.Color.Blastrec.Size = new System.Drawing.Size ( 40 , 24 ) ;lastrec.TabIndex = 8 ;lastrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;lastrec.Text = "尾记录" ;lastrec.Click += new System.EventHandler ( GoLast ) ;//以下是对为显示数据记录而设定的标签和文本框进行初始化,并把记录绑定在不同的绑定到文本框"Text"属性上t_bookid.Location = new System.Drawing.Point ( 184 , 56 ) ;
t_bookid.TabIndex = 9 ;t_bookid.Size = new System.Drawing.Size ( 80 , 20 ) ;t_bookid.DataBindings.Add ( "Text" , myDataSet , "books.bookid" ) ;
t_books.Location = new System.Drawing.Point ( 184 , 264 ) ;t_books.TabIndex = 10 ;t_books.Size = new System.Drawing.Size ( 80 , 20 ) ;t_books.DataBindings.Add ( "Text" , myDataSet , "books.bookstock" ) ;
t_booktitle.Location = new System.Drawing.Point ( 184 , 108 ) ;t_booktitle.TabIndex = 11 ;t_booktitle.Size = new System.Drawing.Size ( 176 , 20 ) ;t_booktitle.DataBindings.Add( "Text" , myDataSet , "books.booktitle" ) ;
t_bookprice.Location = new System.Drawing.Point ( 184 , 212 ) ;t_bookprice.TabIndex = 12 ;t_bookprice.Size = new System.Drawing.Size ( 80 , 20 ) ;t_bookprice.DataBindings.Add ( "Text" , myDataSet , "books.bookprice" ) ;
t_bookauthor.Location = new System.Drawing.Point ( 184 , 160 ) ;t_bookauthor.TabIndex = 18 ;t_bookauthor.Size = new System.Drawing.Size ( 128 , 20 ) ;t_bookauthor.DataBindings.Add ( "Text" , myDataSet , "books.bookauthor" ) ;l_bookid.Location = new System.Drawing.Point ( 24 , 56 ) ;l_bookid.Text = "书本序号:" ;l_bookid.Size = new System.Drawing.Size ( 112, 20 ) ;l_bookid.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;l_bookid.TabIndex = 13 ;l_bookid.TextAlign = System.Drawing.ContentAlignment.MiddleCl_booktitle.Location = new System.Drawing.Point ( 24 , 108 ) ;l_booktitle.Text = "书 名:";l_booktitle.Size = new System.Drawing.Size ( 112 , 20 ) ;l_booktitle.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;l_booktitle.TabIndex = 14 ;l_booktitle.TextAlign = System.Drawing.ContentAlignment.MiddleC
l_bookprice.Location = new System.Drawing.Point ( 24 , 212 ) ;l_bookprice.Text = "价 格:" ;l_bookprice.Size = new System.Drawing.Size ( 112 , 20 ) ;l_bookprice.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookprice.TabIndex = 15 ;l_bookprice.TextAlign = System.Drawing.ContentAlignment.MiddleC
l_books.Location = new System.Drawing.Point ( 24 , 264 ) ;l_books.Text = "书 架 号:" ;l_books.Size = new System.Drawing.Size ( 112 , 20 ) ;l_books.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;l_books.TabIndex = 16 ;l_books.TextAlign = System.Drawing.ContentAlignment.MiddleC
l_bookauthor.Location = new System.Drawing.Point ( 24 , 160 ) ;l_bookauthor.Text = "作 者:" ;l_bookauthor.Size = new System.Drawing.Size ( 112 , 20 ) ;l_bookauthor.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;l_bookauthor.TabIndex = 17 ;l_bookauthor.TextAlign = System.Drawing.ContentAlignment.MiddleC
label1.Location = new System.Drawing.Point ( 49 , 8 ) ;label1.Text = "浏览书籍信息" ;label1.Size = new System.Drawing.Size ( 296 , 24 ) ;label1.ForeColor = System.Drawing.Color.Glabel1.Font = new System.Drawing.Font ( "仿宋" , 15f ) ;label1.TabIndex = 19 ;//对窗体进行设定this.Text = "用做浏览数据库中记录的程序!";this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;this.FormBorderStyle = FormBorderStyle.FixedSthis.ClientSize = new System.Drawing.Size ( 394 , 375 ) ;//在窗体中加入组件this.Controls.Add ( lastrec ) ;this.Controls.Add ( nextrec ) ;this.Controls.Add ( previousrec ) ;this.Controls.Add ( firstrec ) ;this.Controls.Add ( t_books ) ;this.Controls.Add ( t_bookprice ) ;this.Controls.Add ( t_bookauthor ) ;this.Controls.Add ( t_booktitle ) ;this.Controls.Add ( t_bookid ) ;this.Controls.Add ( l_books ) ;this.Controls.Add ( l_bookprice ) ;this.Controls.Add ( l_bookauthor ) ;this.Controls.Add ( l_booktitle ) ;this.Controls.Add ( l_bookid ) ;this.Controls.Add ( label1 ) ;//把对象DataSet和"books"数据表绑定到此myBind对象myBind= this.BindingContext [ myDataSet , "books" ] ;}//按钮"尾记录"对象事件程序
protected void GoLast ( object sender , System.EventArgs e ){myBind.Position = myBind.Count - 1 ;}
//按钮"下一条"对象事件程序protected void GoNext ( object sender , System.EventArgs e ){if ( myBind.Position == myBind.Count -1 )MessageBox.Show ( "已经到了最后一条记录!" ) ;elsemyBind.Position += 1 ;}//按钮"上一条"对象事件程序protected void GoPrevious ( object sender , System.EventArgs e ){if ( myBind.Position == 0 )MessageBox.Show ( "已经到了第一条记录!" ) ;elsemyBind.Position -= 1 ;}//按钮"首记录"对象事件程序protected void GoFirst ( object sender , System.EventArgs e ){myBind.Position = 0 ;}}
&&& 五.总结:
&&& 本文的重点就在于如何用 改变数据集的记录指针和如何让文本框根据记录指针的变化而改变显示内容。虽然此类处理在 比起用其他语言要显得麻烦些。但对于程序设计人员却更灵活了,使得程序设计人员有了更大的发展空间。
上一篇:下一篇:
C#Visual编程
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ?
最受关注的文章:
关键字: &&&&&& 关键字: &&&&&&&&&& 关键字: && 关键字: &&&&&&&& 关键字: &&&&&&&&&&
最新更新文章:
??????????
(没有帐户?)
使用第三方帐号登录:
??????????
Copyright& 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备号-159京公网安备:c#l连接sql2005_百度知道
c#l连接sql2005
sing System.C Initial Catalog=WebShop.StackTrace);
SqlConnection con.Data.G&#92;integrated security=SSPI&quot.Cusing S
catch(Exception e)
con = new SqlConnection(connStr).Text.WriteLine(e;SQL2005.Open();namespace ConsoleApplication3{
class Program
static void Main(string[] args)
String connStr = &quot.SqlClient.WriteLine(&using System.Cserver=localhost&#92;);;using System
提问者采纳
);///returns& &summary&&lt.D/summary&gt.State == ConnectionState.Generic.Tparam&
// 打开链接
conn.State == ConnectionS
conn.Fill(ds);// 执行增删改查操作
//returns&
private int ExecuteNonQuery(string sql)
cmd = new SqlCommand(
&#47.Close();param&gt.SqlC &
private DataTable GetTable(string sql)
SqlDataAdapter da = new SqlDataAdapter(&#47.;using S/
private SqlConnection GetConn()
if (conn == null) conn = new SqlConnection(connStr);/&//
/using S&#47.F &/summary&/using S/returns&&returns&&
/&#47.Dusing S/uid=sa.ExecuteNonQuery();
return 0;/
&lt?我这有个数据库连接你看看;&/
&#47.Open(); &&#47.Broken)
{namespace MyWindows{
public partial class Form1 ; &&lt: Form
private SqlC
private SqlCreturns&/// 得到该表数据
private const string connStr = &
#region 数据库操作
&#47.ComponentM/param name=&quot, GetConn());pwd=1234;
/// &//summary&/database=数据库名&
public Form1()
GetData(); &param name=& 读数据
private void GetData()
DataTable dt = GetTable(&
DataSet ds = new DataSet(),很简单using Ssql&
private SqlDataReader ExecuteReader(string sql)
cmd = new SqlCommand( &//
/returns&summary&returns&gt.ExecuteReader(); &
if (conn.W
else if (&gt.Close();summary&&lt.Closed) conn.Open();summary&summary&/param name=&//using Ssql&param&gt, GetConn());
&select * from 表名&
{ &returns&
/ &&#47.Tables[0];&gt.Close().Close()你要问个什么;using S/
return cmd, GetConn());server=;using System.C
提问者评价
其他类似问题
为您推荐:
其他2条回答
System.WriteLine(&quot.Console,如下修改.C);con: try
con = new SqlConnection(connStr);
catch(Exception e)
}Finally{if(con.WriteLine(e.StackTrace);
con.Open){con.close()缺少关闭数据库的操作.State==ConnectionS成功&quot.Close().Open()
Server 2005时出现的.归纳了一下,由以下几个原因:
1.数据库引擎没有启动.
有两种启动方式:
(1)开始-&程序-&Microsoft SQL Server 2005-&SQL Server 2005外围应用配置器,在打开的界面单击&服务的连接的外围应用配置器&,在打开的界面中找到Database Engine,单击&服务&,在右侧查看是否已启动,如果没有启动可单击&启动&,并确保&启动类型&为自动,不要为手动,否则下次开机时又要手动启动;
(2)可打开:开始-&程序Microsoft SQL Server 2005-&配置工具-&SQL Server Configuration Manager,选中SQL Server 2005服务中SQL Server(MSSQLSERVER) ,并单击工具栏中的&启动服务&按钮把服务状态改为启动;
使用上面两种方式时,有时候在启动的时候可能会出现错误,不能启动...
sql2005的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 c 连接数据库 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信