WinForm CheckBox
CRUD Operations Series
- Part 1 TextBox control
- Part 2 CheckBox control
- Part 3 RadioButton control
- Part 4 DateTimePicker control
- Part 5 ComboBox control
- Part 6 PictureBox control
- Part 7 TabControl control
CODE:
Use dbABC;
Go
ALTER TABLE tbl_Employee
ADD IsVB BIT null
CODE:
Use dbABC;
Go
ALTER PROCEDURE [dbo].[usp_AddEmployee]
(
@FirstName NVARCHAR(50),
@LastName NVARCHAR(50),
@Email NVARCHAR(50),
@IsVB BIT
)
As
BEGIN
INSERT INTO [dbo].[tbl_Employee]([FirstName],[LastName],[Email],[IsVB])
VALUES (@FirstName, @LastName , @Email, @IsVB)
END
TEXT
IMAGEIMAGE
IMAGE
IMAGE ADD TWO MORE CHECKBOX CONTROLS
CODE:
ALTER TABLE tbl_Employee
ADD IsJava BIT null, IsCSharp BIT null
CODE:
ALTER PROCEDURE [dbo].[usp_AddEmployee]
(
@FirstName NVARCHAR(50),
@LastName NVARCHAR(50),
@Email NVARCHAR(50),
@IsVB BIT,
@IsJava BIT,
@IsCSharp BIT
)
As
BEGIN
INSERT INTO [dbo].[tbl_Employee]([FirstName]
,[LastName],[Email]
,[IsVB],[IsJava],[IsCSharp])
VALUES (@FirstName, @LastName , @Email, @IsVB, @IsJava, @IsCSharp)
END
CODE:
public partial class EmployeeForm : Form
{
public EmployeeForm()
{
InitializeComponent();
}
private void SubmitButton_Click(object sender, EventArgs e)
{
InsertIntoDatabase();
}
private void InsertIntoDatabase()
{
try
{
string connString = ConfigurationManager.ConnectionStrings["abccs"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = conn;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "usp_AddEmployee";
command.Parameters.AddWithValue("@FirstName", FirstNameTextBox.Text);
command.Parameters.AddWithValue("@LastName", LastNameTextBox.Text);
command.Parameters.AddWithValue("@Email", EmailTextBox.Text);
command.Parameters.AddWithValue("@IsVB", IsVBCheckBox.Checked);
command.Parameters.AddWithValue("@IsJava", IsJavaCheckBox.Checked);
command.Parameters.AddWithValue("@IsCSharp", IsCSharpCheckBox.Checked);
//Execute the insert query
conn.Open();
command.ExecuteNonQuery();
MessageBox.Show("Record inserted successfully.", "Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Insertion Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
OUTPUT
© अजीत कुमार, सर्वाधिकार सुरक्षित।
इस आलेख को उद्धृत करते हुए इस लेख के लिंक का भी विवरण दें। इस आलेख को कॉपीराइट सूचना के साथ यथावत साझा करने की अनुमति है। कृपया इसे ऐसे स्थान पर साझा न करें जहाँ इसे देखने के लिए शुल्क देना पडे।
No comments:
Post a Comment