我有兩個數據庫電影(ID,名稱)和SessionsCinema(ID,SessionTime,電影,大廳,價格)。 id - 是自動增量行。斷開ADO.Net模式,從數據庫加載到Sql表
我在ado.net上工作與ms sql數據庫斷開連接的模式。 我想將設置保存到SQL表。 對錶格「電影」的更改是可以的,但對於表格「SessionsCinema」有一些錯誤。
//connection start
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "MYPC\SQLEXPRESS";
builder.InitialCatalog = "Cinema";
builder.IntegratedSecurity = true;
SqlConnection conn = new SqlConnection(builder.ConnectionString);
//connection end
//Movies start
SqlCommand inscmd = new SqlCommand();
inscmd.CommandText = "Insert into Movies (name) values(@name); select id = @@IDENTITY from Movies";
inscmd.Connection = conn;
inscmd.Parameters.Add("@name", SqlDbType.NVarChar, 250, "name");
SqlDataAdapter adapter = new SqlDataAdapter(inscmd);
adapter.InsertCommand = inscmd;
adapter.Update(Movies);
//Movies end
//SessionsCinema start
inscmd = new SqlCommand();
inscmd.CommandText = "Insert into SessionsCinema (SessionTime, movie, hall, price) values(@SessionTime, @movie, @hall, @price); select id = @@IDENTITY from SessionsCinema";
inscmd.Connection = conn;
inscmd.Parameters.Add("@SessionTime,@movie,@hall,@price", SqlDbType.NVarChar, 250, "SessionTime,movie,hall,price");
adapter = new SqlDataAdapter(inscmd);
adapter.InsertCommand = inscmd;
adapter.Update(SessionsCinema);
//SessionsCinema end
究竟是什麼錯誤? –
','附近的語法不正確。 必須聲明標量變量「@SessionTime」 – user2963950