在aspnet中创建多个表 [英] Create mutiple tables in aspnet

查看:76
本文介绍了在aspnet中创建多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我想在数据库中创建至少145个表,每个表都需要时间来创建单个表,在aspnet中保存并进行查询。 />


我希望在aspnet中的数据库中制作145个表格,就像我们在sql工作室管理中一样。



关于aspnet webform,请帮助我。



问候

Tahir

解决方案

PL。试试这个..





 使用(SqlConnection con =  new  SqlConnection(conStr))
// conStr是连接字符串
{
尝试
{
// < span class =code-comment>
// 打开SqlConnection
//
con.Open();
//
// 以下代码对创建表使用SqlCommand - 多个表需要相同
//
使用(SqlCommand command = new SqlCommand( 如果不存在(从sysobjects中选择名称,其中name ='table1')CREATE TABLE table1 (First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime);,con))
命令。的ExecuteNonQuery();
使用(SqlCommand command = new SqlCommand( 如果不存在(从sysobjects中选择名称,其中name ='table2')CREATE TABLE table2(First_Name1 char(50),Last_Name1 char(50),Address1 char(50) ),City1 char(50),Country1 char(25),Birth_Date1 datetime);,con))
command.ExecuteNonQuery();

}
catch (例外情况)
{
MessageBox.Show(ex.Message);
}
}


Dear Friends,

I want to make atleast 145 tables in the database, each take time to create single table , save and make queries in aspnet.

I want that to make 145 tables in database in aspnet MANUALLY same like we do in sql studio management

Please help me in this regard for aspnet webform.

Regards
Tahir

解决方案

pl. try with this..


using (SqlConnection con = new SqlConnection(conStr))
              //conStr is connection String
      {
              Try
      {
          //
          // Open the SqlConnection
          //
          con.Open();
          //
          // The following code uses an SqlCommand for create table - need same for multiple table
          //
          using (SqlCommand command = new SqlCommand("If not exists (select name from sysobjects where name = 'table1') CREATE TABLE table1(First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime)";, con))
          command.ExecuteNonQuery();
          using (SqlCommand command = new SqlCommand("If not exists (select name from sysobjects where name = 'table2') CREATE TABLE table2(First_Name1 char(50),Last_Name1 char(50),Address1 char(50),City1 char(50),Country1 char(25),Birth_Date1 datetime)";, con))
          command.ExecuteNonQuery();

      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.Message);
      }
  }


这篇关于在aspnet中创建多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆