zoukankan      html  css  js  c++  java
  • 如何在代码中生成数据库?

    先连接到master数据库, 然后执行建立数据库的sql语句, 就可以了.

    示例代码如下:

    void button_Click(object sender, RoutedEventArgs e)

     {

       string connectionString = "Data Source=192.168.0.8;Initial Catalog=master;"

                    +"Persist Security Info=True;User ID=sa;Password=sa";

                SqlConnection m_sqlConn = new SqlConnection(connectionString);

     

                string strCommand = "USE master;    IF DB_ID (N'mytest') IS NOT NULL      DROP DATABASE mytest;  CREATE DATABASE mytest;  SELECT name, size, size*1.0/128 AS [Size in MBs]  FROM sys.master_files WHERE name = N'mytest';";

     

     

               SqlCommand command = new SqlCommand(strCommand,m_sqlConn);

                m_sqlConn.Open();

                command.ExecuteNonQuery();

                m_sqlConn.Close();

            }

     

  • 相关阅读:
    foreach和each
    one
    存储
    动态添加
    百度描点
    php环境配置
    图文并茂
    css实现鼠标移上去变大,旋转,转别人的额
    vagrant box打包前的准备
    VirtualBox压缩打包
  • 原文地址:https://www.cnblogs.com/dunnice/p/640074.html
Copyright © 2011-2022 走看看