none
Create Table in database on the fly RRS feed

  • Question

  • I have a requirement like:

    Take a input Table Name , Fields and fields type from user. As per user input create table in database.

    I don't want to use reflection.

    Can anybody have any idea about this.

    Thanks,

    Vaibhav

    Friday, June 3, 2016 1:24 PM

Answers

  • First check whether table exists or not. If not exists then it create the table.

    var commandStr= "If not exists (select name from sysobjects where name = 'Customer') CREATE TABLE Customer(First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime)";

    using (SqlCommand command = new SqlCommand(commandStr, con))
    command.ExecuteNonQuery();

    Friday, June 3, 2016 1:28 PM

All replies

  • First check whether table exists or not. If not exists then it create the table.

    var commandStr= "If not exists (select name from sysobjects where name = 'Customer') CREATE TABLE Customer(First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime)";

    using (SqlCommand command = new SqlCommand(commandStr, con))
    command.ExecuteNonQuery();

    Friday, June 3, 2016 1:28 PM
  • This as nothing to do with the ADO.NET Entity Framework. You should find a more appropriate forum.  
    Saturday, June 4, 2016 4:19 PM