我正在研究Windows窗體應用程序,我創建了一個包含房間名稱,大小和LAB的房間窗體。如何在C#中的SQL Server數據庫中保存CheckBox值
在數據庫中的表中包含的列RoomName
(varchar
),Size
(int
),和LAB
(bit
)。
這是ADD_ROOM
存儲過程:
CREATE PROCEDURE [dbo].[ADD_ROOM]
@NAME_ROOM VARCHAR(50),
@SIZE INT,
@LAB BIT
AS
INSERT INTO [dbo].[ROOM] ([NAME_ROOM], [SIZE], [LAB])
VALUES (@NAME_ROOM, @SIZE, @LAB)
這裏是ADD_ROOM.cs
:
class CLS_ADD_ROOM
{
public void ADD_ROOM(string NAME_ROOM,int SIZE,Boolean LAB)
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DAL.Open();
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@NAME_ROOM", SqlDbType.VarChar, 50);
param[0].Value = NAME_ROOM;
param[1] = new SqlParameter("@SIZE", SqlDbType.Int);
param[1].Value = SIZE;
param[2] = new SqlParameter("@LAB", SqlDbType.Bit);
param[2].Value = LAB;
DAL.ExecuteCommand("ADD_ROOM", param);
DAL.Close();
}
public void UPDATE_ROOM(string ID_ROOM, string NAME_ROOM, int SIZE, bool LAB)
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DAL.Open();
SqlParameter[] param = new SqlParameter[4];
param[0] = new SqlParameter("@ID_ROOM", SqlDbType.Int);
param[0].Value = ID_ROOM;
param[1] = new SqlParameter("@NAME_ROOM", SqlDbType.VarChar, 50);
param[1].Value = NAME_ROOM;
param[2] = new SqlParameter("@SIZE", SqlDbType.Int);
param[2].Value = SIZE;
param[3] = new SqlParameter("@LAB", SqlDbType.Bit);
param[3].Value = LAB;
DAL.ExecuteCommand("UPDATE_ROOM", param);
DAL.Close();
}
而在ADD ROOM FORM
private void button1_Click(object sender, EventArgs e)
{
ROOM.ADD_ROOM(TXT_ROOM_NAME.Text, Convert.ToInt32(TXT_ROOM_SIZE.Text), Convert.ToBoolean(CHECK_LAB.CheckState));
MessageBox.Show(" The Room has been added successfully", "ADD PROCEDURE", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.dataGridView1.DataSource = ROOM_VIEW.GET_ALL_ROOMS();
}
後面按鈕ADD Room
代碼和錯誤是
輸入字符串的不正確的格式
你能添加所有異常的堆棧跟蹤嗎? – Fabio 2014-10-09 09:03:55
http://im84.gulfup.com/wFq8fH.jpg – 2014-10-09 09:14:09
http://im84.gulfup.com/wFq8fH.jpg @Fabio – 2014-10-09 09:21:36