I have this code to create new sql table when i execute this its shows me this error which is on screenshot. In my db there ise not such table. it shows this error any name of table. can anyone help me?
public void Create(string TName, string ConString)
{
try
{
using (SqlCommand cmd = new SqlCommand("CREATE TABLE [dbo].['" + TName + "']("
+ "[ID] [int] IDENTITY(1,1) NOT NULL,"
+ "[DateTime] [date] NOT NULL,"
+ "[BarCode] [nvarchar](max) NOT NULL,"
+ "[ArtNumber] [nvarchar](max) NOT NULL,"
+ "[ProductName] [nvarchar](50) NOT NULL,"
+ "[Quantity] [int] NOT NULL,"
+ "[SelfPrice] [decimal](18, 2) NOT NULL,"
+ "[Price] [decimal](18, 2) NOT NULL,"
+ "[Disccount] [int] NULL,"
+ "[Comment] [nvarchar](max) NULL,"
+ "CONSTRAINT ['" + TName + "'] PRIMARY KEY CLUSTERED "
+ "("
+ "[ID] ASC"
+ ")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"
+ ") ON [PRIMARY]", new SqlConnection(ConString)))
{
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
}
catch (Exception)
{
throw;
}
}
In SSMS, in Object Explorer, connect to the instance of Database Engine that contains the database to be modified. In Object Explorer, expand the Databases node and then expand the database that will contain the new table. In Object Explorer, right-click the Tables node of your database and then click New Table.
You can code SQL statements in a C or C++ program wherever you can use executable statements. Each SQL statement in a C or C++ program must begin with EXEC SQL and end with a semicolon (;). The EXEC and SQL keywords must appear on one line, but the remainder of the statement can appear on subsequent lines.
C is an alias for the results from the sub-query (select min(A. bidvalue) as ....). This subquery will product a result set which behaves like a table for the duration of the query. To refer to this result set and its columns, it was given the alias name "C" and all C.
To undestand the difference between a language like C and SQL is that basically SQL is a specialized type of language that is concerned with database operations. C is less concerned with accessing the data than with how the whole application will work.
You're using the same name for your table and its primary key. Try instead "CONSTRAINT ['pk_" + TName + "'] PRIMARY KEY CLUSTERED "
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With