| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 614 人关注过本帖
标题:求助:判断是否存在数据库
只看楼主 加入收藏
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
求助:判断是否存在数据库

源代码:主要是判断是否存在数据库mobile
 private void timer1_Tick(object sender, EventArgs e)
        {
            string strconnx = "User ID=sa;Password=123;Initial Catalog=master;Data Source=ycbbg";
            string sqlx = "SELECT name FROM sys.databases WHERE name = N'mobile'";
            int i = Convert.ToInt32(BaseClass.parameter_sql.ExecuteScalar(strconnx, CommandType.Text, sqlx,null));
            if (i > 1)
            {
                frmLogin lo = new frmLogin();
                lo.Show();
            }
            else
            {
                try
                {
                    
                    Directory.CreateDirectory(Application.StartupPath + "\\DataBase");
                    string sql2 = "CREATE DATABASE [mobile] ON  PRIMARY ( NAME = N'mobile', FILENAME = N'" + Application.StartupPath + "\\DataBase\\mobile.mdf' , SIZE = 6144KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) ( NAME = N'mobile_log', FILENAME = N'" + Application.StartupPath + "\\DataBase\\mobile_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)  CREATE TABLE [dbo].[tb_telsend]([id] [int] IDENTITY(1,1) NOT NULL,[telnum] [varchar](50) NULL,[telcontent] [varchar](max) NULL,[teltime] [varchar](50) NULL,CONSTRAINT [PK_tb_telsend] PRIMARY KEY CLUSTERED([id] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] CREATE TABLE [dbo].tb_tel]([id] [int] IDENTITY(1,1) NOT NULL,[username] [varchar](50) NULL,[usersex] [varchar](10) NULL,[usertel] [varchar](50) NULL, CONSTRAINT [PK_tb_tel] PRIMARY KEY CLUSTERED([id] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] CREATE TABLE [dbo].[worker]([id] [int] IDENTITY(1,1) NOT NULL,[jh] [varchar](50) NULL,shfzh][varchar](50) NULL,[danwei] [varchar](50) NULL,[xm] [varchar](50) NULL,[sex] [varchar](2) NULL,[address] [varchar](200) NULL,[phone] [varchar](50) NULL,[dnt]datetime] NULL,) ON [PRIMARY] CREATE TABLE [dbo].[times]([id] [int] IDENTITY(1,1) NOT NULL,[lx] [varchar](50) NULL,[days] [varchar](50) NULL,[times] [varchar](50) NULL,STRAINT [PK_times] PRIMARY KEY CLUSTERED([id] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] CREATE TABLE [dbo].[tb_admin]([id] [int] IDENTITY(1,1) NOT NULL,[adminusername] [varchar](50) NULL,[adminuserpwd] [varchar](50) NULL,[power] [nchar](1) NULL,CONSTRAINT [PK_tb_admin] PRIMARY KEY CLUSTERED([id] ASC)WITH(IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] CREATE TABLE [dbo].[tb_note]([id] [int] IDENTITY(1,1) NOT NULL,[type] [varchar](50) NULL,[note] [varchar](max) NULL,CONSTRAINT [PK_tb_note] PRIMARY KEY CLUSTERED([id] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] CREATE TABLE [dbo].[tb_resvice]([id] [int] IDENTITY(1,1) NOT NULL,[smsnum] [varchar](50) NULL,[smscontent] [varchar](max) NULL,CONSTRAINT [PK_tb_resvice] PRIMARY KEY CLUSTERED([id] ASC)WITH (IGNORE_DUP_KEY = OFF) ON[PRIMARY]) ON [PRIMARY]";

                    BaseClass.parameter_sql.ExecuteNonQuery(strconnx, CommandType.Text, sql2, null);
                }
                catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
        
    }
            }
         

        }



出错:int i = Convert.ToInt32(BaseClass.parameter_sql.ExecuteScalar(strconnx, CommandType.Text, sqlx,null));
输入字符串的格式不正确。

搜索更多相关主题的帖子: 数据库 判断 
2010-09-01 16:18
saitor
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:5
帖 子:373
专家分:1520
注 册:2009-5-18
收藏
得分:14 
SELECT * FROM dbo.sysdatabases WHERE name = N'mobile' name是关键字
2010-09-01 17:13
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
还是没解决!!!

http://www.
2010-09-02 15:50
快速回复:求助:判断是否存在数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030541 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved