두 테이블이 있습니다.SqlDataAdapter 문제
고객은 (INT 아이디, nvachar 이름 (250), INT 연령)
보너스 (INT 아이디, INT CUSTOMER_ID 참조 고객 (ID), INT의 someAmount)
나는 추가해야 고객 및 보너스에 관한 정보를 삭제, 갱신하십시오.
새 고객을 추가하면 programm가 자동으로 테이블 보너스에서이 고객에 대한 새로운 항목을 만듭니다.
고객을 삭제하면 programm는 테이블 보너스로이 고객에 대한 정보를 삭제합니다.
SQL 데이터베이스에 저장하는 데 문제가 있습니다.
//Bonus
SqlCommand inscmdT = new SqlCommand();
inscmdT.CommandText = "Insert into Bonus (customer_id, someAmount) values(@customer_id, @someAmount); select id = @@IDENTITY from Bonus";
inscmdT.Connection = conn;
inscmdT.Parameters.Add("@customer_id", SqlDbType.Int, sizeof(Int32), "customer_id");
inscmdT.Parameters.Add("@someAmount", SqlDbType.Int, sizeof(Int32), "someAmount");
SqlCommand updcmdT = new SqlCommand();
updcmdT.CommandText = "UPDATE Bonus SET customer_id = @customer_id, someAmount = @someAmount WHERE id = @id";
updcmdT.Connection = conn;
updcmdT.Parameters.Add("@customer_id", SqlDbType.Int, sizeof(Int32), "customer_id");
updcmdT.Parameters.Add("@someAmount", SqlDbType.Int, sizeof(Int32), "someAmount");
updcmdT.Parameters.Add("@id", SqlDbType.Int, sizeof(Int32), "id");
SqlCommand delcmdT = new SqlCommand();
delcmdT.CommandText = "DELETE FROM Bonus WHERE id = @id";
delcmdT.Parameters.Add("@id", SqlDbType.Int, sizeof(Int32), "id");
delcmdT.Connection = conn;
//Customers
SqlCommand inscmdS = new SqlCommand();
inscmdS.CommandText = "Insert into Customers (SessionTime, movie, hall, age) values(@SessionTime, @age); select id = @@IDENTITY from Customers";
inscmdS.Connection = conn;
inscmdS.Parameters.Add("@SessionTime", SqlDbType.NVarChar, 250, "SessionTime");
inscmdS.Parameters.Add("@age", SqlDbType.Int, sizeof(Int32), "age");
SqlCommand updcmdS = new SqlCommand();
updcmdS.CommandText = "UPDATE Customers SET SessionTime = @SessionTime, age = @age WHERE id = @id ";
updcmdS.Connection = conn;
updcmdS.Parameters.Add("@SessionTime", SqlDbType.NVarChar, 250, "SessionTime");
updcmdS.Parameters.Add("@age", SqlDbType.Int, sizeof(Int32), "age");
updcmdS.Parameters.Add("@id", SqlDbType.Int, sizeof(Int32), "id");
SqlCommand delcmdS = new SqlCommand();
delcmdS.CommandText = "DELETE FROM Customers WHERE id = @id";
delcmdS.Parameters.Add("@id", SqlDbType.Int, sizeof(Int32), "id");
delcmdS.Connection = conn;
어떻게 제대로 삭제, 삽입에 SqlDataAdapter를 쓰기 위해, 업데이트 :
나는이 SQL-명령이?
Visual Studio를 사용하고 있습니까? – RadioSpace