C# - Create SQL Server table programmatically

前端 未结 7 2380
温柔的废话
温柔的废话 2020-12-15 06:37

I am trying to create a SQL Server table programmatically. Here is the code.

using (SqlConnection con = new SqlConnection(conStr))
{

    try
    {
        /         


        
7条回答
  •  清歌不尽
    2020-12-15 07:06

    Try this

    Check if table have there , and drop the table , then create

    using (SqlCommand command = new SqlCommand("IF EXISTS (
    SELECT *
    FROM sys.tables
    WHERE name LIKE '#Customer%')
    DROP TABLE #Customer CREATE TABLE Customer(First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime);", con))
    

提交回复
热议问题