string date = p_text_data.Text;
string sql = @"INSERT INTO Warehouse (title,count,price,date) ";
try
{
using (SqlConnection connection = ConnectToDataBase.GetConnection())
{
SqlCommand command = new SqlCommand(sql, connection);
for (int i = 0; i < mdc.Count; i++)
{
sql += "SELECT @title" + i + ",@count" + i + ",@price" + i + ",@date" + i + " ";
command.Parameters.AddWithValue("@title" + i, mdc[i].Title);
command.Parameters.AddWithValue("@count" + i, mdc[i].Count);
command.Parameters.AddWithValue("@price" + i, mdc[i].Price);
command.Parameters.AddWithValue("@date" + i, Conver_Data(date));
if (mdc.Count-1 != i)
sql += "UNION ALL ";
}
sql += " ;";
connection.Open();// *sql
string id_Partner = command.ExecuteScalar().ToString();
}
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
*sql = "INSERT INTO Warehouse (title,count,price,date) SELECT @title0,@count0,@price0,@date0 UNION ALL SELECT @title1,@count1,@price1,@date1 ;"
Then he flies an exception
Incorrect syntax near ')'
clarify - count - int, price - double, date - Date
what am I doing wrong?
edit: Table
CREATE TABLE [dbo].[Warehouse] (
[ID] int IDENTITY(1, 1) NOT NULL,
[title] char(30) COLLATE Cyrillic_General_CI_AS NULL,
[count] int NULL,
[price] float NULL,
[date] datetime NULL,
CONSTRAINT [PK__Warehous__3214EC277F60ED59] PRIMARY KEY CLUSTERED ([ID])
)
ON [PRIMARY]
GO
I'm used SQL Server 2008