I'm working on a Windows forms app, I created a room form which contains room name, size, and LAB.
The table in the database contains columns RoomName (varchar), Size (int), and LAB (bit).
This is the ADD_ROOM stored procedure:
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)
Here is 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();
}
And the code behind button ADD Room in 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();
}
And the error is
Input string was not in a correct format