Simple Windows Application "PhoneBook Application"
PART-1
Step :-1
Create a Window Application
like this Image :-1
Step :-2
Design for the FORM-1
Write Code For The CREATE button
private void btnCreate_Click(object sender, EventArgs e)
{
try
{
SqlConnection _cON = new SqlConnection("Data Source=.;Initial Catalog=VickyRajBlogs;Integrated Security=True");
_cON.Open();
SqlCommand _cMD = new SqlCommand("Insert into PhoneBook values('" + txtFirstName.Text + "','" + txtLastName.Text + "'," + txtContact.Text + ")", _cON);
int res = _cMD.ExecuteNonQuery();
_cON.Close();
}
catch (Exception ex)
{
MessageBox.Show("ERROS" + ex.ToString());
}
finally
{
txtFirstName.Text = string.Empty;
txtLastName.Text = string.Empty;
txtContact.Text = string.Empty;
}
}
Write Code For The "PHONEBOOK" button
private void btnPhoneBook_Click(object sender, EventArgs e)
{
PhoneBook _objPhoneBook = new PhoneBook();
_objPhoneBook.Show();
}
Write Code For The "CANCEL" button
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
PART-2
Step :-1
Add a Window Application Form in This Application
like this Image :-3
Write Code For The ADD New Contact button
private void btnAddNewCOntact_Click(object sender, EventArgs e)
{
Form1 _ObjForm1 = new Form1();
_ObjForm1.Show();
}
Write Code For The Contact button
private void btnContacts_Click(object sender, EventArgs e)
{
try
{
showAll();
}
catch (Exception ex)
{
MessageBox.Show("ERROS" + ex.ToString());
}
}
private void showAll()
{
SqlConnection _cON = new SqlConnection("Data Source=.;Initial Catalog=VickyRajBlogs;Integrated Security=True");
_cON.Open();
SqlCommand _cMD = new SqlCommand("Select * from PhoneBook", _cON);
SqlDataAdapter _sDA = new SqlDataAdapter(_cMD);
DataTable _dT = new DataTable();
_sDA.Fill(_dT);
gRIDPhoneBook.DataSource = _dT;
_cON.Close();
}
// showAll() method create for the Load Event
private void PhoneBook_Load(object sender, EventArgs e)
{
showAll();
}
Write Code For The CANCELbutton
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
PART-3
DataBase Connection
Write Code For The Create Table
Create Table PhoneBook
(
SrNo int IDENTITY(1,1) Primary Key ,
FirstName nvarchar(50),
LastName nvarchar(50) ,
ContactNo nvarchar(50)
)
Write Code For The Select Command
Select * from PhoneBook
Write Code For The Insert Values into Table
Insert into PhoneBook values('VICKY','RAJ',9654388184)
PART-4
See The Results:-----
Form-1
Form-2
I hope you Enjoyed With this Application...
& THANK YOU to visit this Page...!!
No comments:
Post a Comment