您的位置:程序门 -> .net技术 -> c#



数据库连接问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


数据库连接问题
发表于:2007-01-24 23:44:06 楼主
using   system;
using   system.collections.generic;
using   system.componentmodel;
using   system.data;
using   system.drawing;
using   system.text;
using   system.windows.forms;
using   system.data.common;
using   system.data.sqlclient;
using   system.data.sqltypes;

namespace   windowsapplication1
{
        public   partial   class   form1   :   form
        {
                public   form1()
                {
                        initializecomponent();
                }

                private   void   button1_click(object   sender,   eventargs   e)
                {
                        sqlconnection   myconnection   =   new   sqlconnection(@ "server=localhost;database=aaa.mdf1;uid=;pwd=;connect   timeout=30;database=aaa; ");

                        myconnection.open();
                        sqldataadapter   sd   =   new   sqldataadapter( "select   *   from   table1 ",   myconnection);
                        sqlcommandbuilder   ssd   =   new   sqlcommandbuilder(sd);
                        dataset   thisdset   =   new   dataset();
                        sd.fill(thisdset,   "table1 ");
                        sqlcommand   command   =   new   sqlcommand();
                        sqldatareader   reader   =   command.EXECutereader();
                        datarow   findrow   =   thisdset.tables[ "table1 "].rows.find( "111 ");

                        if   (findrow   ==   null)
                        {
                                if   (messagebox.show( "11111 "   +   "用户名不存在 ",   "错误信息! ",   messageboxbuttons.okcancel,   messageboxicon.error)
                                            ==   dialogresult.ok)
                                {
                                        messagebox.show( "qqqqqqqqqq ");
                                }
                                else
                                {
                                        messagebox.show( "1111111111111111 ");
                                }
                        }
                        else
                        {
                                messagebox.show( "系统致命错误! ",   "错误信息! ",   messageboxbuttons.okcancel,   messageboxicon.error);

                        }
                }
        }
}
为什么连不上数据库
发表于:2007-01-24 23:59:531楼 得分:0
出现的是什么异常,贴出来看看...
发表于:2007-01-25 00:15:592楼 得分:0
sqlconnection   myconnection   =   new   sqlconnection(@ "server=localhost;database=aaa.mdf1;uid=;pwd=;connect   timeout=30;database=aaa; ");

怎么两个database
发表于:2007-01-25 00:36:353楼 得分:0
(@ "server=localhost;database=aaa.mdf1;uid=;pwd=;connect   timeout=30;database=aaa; ");
中的@可以不要吧
发表于:2007-01-25 08:04:564楼 得分:0
我知道啊.可以图片怎么贴的出来啊.
就是error   40错误
不能于远程服务器连接.
发表于:2007-01-25 08:32:465楼 得分:0
同问,你的连接字符串中怎么有两个database啊? "..database=aaa.mdf..database=aaa "???
发表于:2007-01-25 08:38:156楼 得分:0
"server=.;database=aaa;uid=;pwd=; "
这样就可以了!


快速检索

最新资讯
热门点击