Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
KaushalJB 25-Jun-14 4:30am    
You mean to say u stuck with creating DBs in Asp.net SQL database that Visual Studio provides ??
Debabrata_Das 25-Jun-14 5:27am    
Hello friend, as per my understanding of your query:
You have a web application developed in ASP.NET which allows user to create tables. The activity is time consuming as user has to write the CREATE TABLE statements manually. Now you want to provide feature to create table just like we create table in SQL Server.

Please correct me if I'm wrong.
- DD
tahirgr8_2000 25-Jun-14 6:28am    
Dear Kasushal and Debarata, you are right about my queries. How i will create table in visual studio by code or manually as we do in sql studio.

1 solution

pl. try with this..


C#
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);
      }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900