Friday, 6 July 2012

Connectivity ADO.NET with Connected Mode (for begainer Student...)


This code for Connectivity with DataBase (Ado.NET with Sql Server ) in Connected Mode.........


//create  table  Customer  in Database which name is Test  ........................

use test
Create table Customer(SrNo int primary key,FirstName nvarchar(50),LastName nvarchar(50),Dob DateTime)

select * from Customer





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using this namespace  for Connectivity  with ADO.NET........................
using System.Data.SqlClient;

namespace ConnectivityWithSql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Code For Save data in DataBase .......................
private void btnsave_Click(object sender, EventArgs e)
{
try
{
//create  object  of Connection Class..................
SqlConnection con = new SqlConnection();
//Set Connection String property of Connection object..................
con.ConnectionString = @"Data Source=KUSH-PC\KUSH;Initial Catalog=test;Integrated Security=True";
//Open Connection..................
con.Open();
//Create object of Command Class................
SqlCommand cmd = new SqlCommand();
//set Connection Property  of  Command object.............
cmd.Connection = con;
//Set Command type of command object
//1.StoredProcedure
//2.TableDirect
//3.Text   (By Default)
cmd.CommandType = CommandType.Text;
//Set Command text Property of command object.........
cmd.CommandText = "insert into Customer(SrNo,FirstName,LastName,Dob) values(" + Convert.ToInt32(txtcustomerid.Text) + ",'" + txtfname.Text + "','" + txtlname.Text + "','" +Convert.ToDateTime(txtdob.Text) + "')";

//Execute command by calling following method................
   1.ExecuteNonQuery()
       It  query using for  insert,delete,update command...........
 2.ExecuteScalar()
     It  query return a single value and insert all record...................(using select,insert command)
//   3.ExecuteReader()
//      It  query return one or more than one record....................................

cmd.ExecuteNonQuery();


MessageBox.Show("Data Saved");
TextBoxClear();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}




}
//Code For Serach data From DataBase with SrNo
private void btnsearch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Customer where SrNo='" + Convert.ToInt32(txtcustomerid.Text) + "'";
cmd.Connection = con;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{

txtfname.Text = dr["FirstName"].ToString();
txtlname.Text = dr[2].ToString();
txtdob.Text = dr.GetDateTime(3).ToShortDateString();
}
else
MessageBox.Show("Record not found", "No record", MessageBoxButtons.OK, MessageBoxIcon.Information);
con.Close();


}
//Code For Delete data From DataBase with SrNo
private void btndelete_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Delete from Customer where SrNo='" + Convert.ToInt32(txtcustomerid.Text) + "'";
cmd.Connection = con;
int i=cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("Data delete Successfully for SrNo" + txtcustomerid.Text);
TextBoxClear();
}
else
{
MessageBox.Show("Record not found", "No record", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
con.Close();
}
//Code For Update data From DataBase with SrNo
private void btnupdate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Update Customer set  FirstName='" + txtfname.Text + "',LastName='" + txtlname.Text + "',Dob='" +Convert.ToDateTime(txtdob.Text) + "' where SrNo='"+Convert.ToInt32(txtcustomerid.Text)+"'";
cmd.Connection = con;
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("Data updated Successfully for SrNo" + txtcustomerid.Text);
TextBoxClear();
}
else
{
MessageBox.Show("Record not found", "No record", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
con.Close();
}
//Code For Searching First  Row From DataBase
private void btnfirst_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Customer";
cmd.Connection = con;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
txtcustomerid.Text = dr.GetInt32(0).ToString();
txtfname.Text = dr["FirstName"].ToString();
txtlname.Text = dr.GetString(2);
txtdob.Text = dr.GetDateTime(3).ToShortDateString();
}
else
{
MessageBox.Show("Record not found", "No record", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
con.Close();
}
//Code For Searching Last  Row From DataBase
private void btnlast_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Customer";
cmd.Connection = con;
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{

txtcustomerid.Text = dr.GetInt32(0).ToString();
txtfname.Text = dr["FirstName"].ToString();
txtlname.Text = dr.GetString(2);
txtdob.Text = dr.GetDateTime(3).ToShortDateString();
}
con.Close();
}
//Code For Searching Previouse  Row From DataBase
private void btnprevious_Click(object sender, EventArgs e)
{
string a = txtcustomerid.Text;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Customer";
cmd.Connection = con;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (a == dr[0].ToString())
{
return;
}
txtcustomerid.Text = dr.GetInt32(0).ToString();
txtfname.Text = dr["FirstName"].ToString();
txtlname.Text = dr.GetString(2);
txtdob.Text = dr.GetDateTime(3).ToShortDateString();
}
con.Close();
}
//Code For Searching Next  Row From DataBase
private void btnnext_Click(object sender, EventArgs e)
{
string a = (txtcustomerid.Text);
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\KUSH;Initial Catalog=test;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Customer";
cmd.Connection = con;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (a == dr[0].ToString())
{
dr.Read();
txtcustomerid.Text = dr.GetInt32(0).ToString();
txtfname.Text = dr["FirstName"].ToString();
txtlname.Text = dr.GetString(2);
txtdob.Text = dr.GetDateTime(3).ToShortDateString();
return;
}
}
con.Close();

}
//Blank All TextBox
private void TextBoxClear()
{
// different method for blank  TextBox Text.......................

txtcustomerid.Text = "";
txtfname.Clear();
txtlname.Text = String.Empty;
txtdob.Text = "";


}

private void btnClear_Click(object sender, EventArgs e)
{
TextBoxClear();
}

private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}


93 comments:

  1. Hello Kush Sir ,


    pls iam the new one for windows applications and i want to know the using joinquery when the combobox control seleted that record must be displayed in textbox from other tables links values ,at the same can you give me the step by step above your code example for all controls using in windows applications in c# pls mail my id:santhoshpandiyar@yahoo.com

    ReplyDelete
  2. Sir,
    Your tutorial going to provide strengthen in .Net. This is easy to understand. Thank you so much for your kind effort.
    Samar Naim

    ReplyDelete
  3. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete

  4. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
    Advanced Selenium Training in Chennai

    ReplyDelete
  5. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
    Best Java Training Institute Chennai

    ReplyDelete
  6. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

    Amazon Web Services Training in Chennai

    Best Java Training Institute Chennai




    ReplyDelete
  7. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    RPA Training in Bangalore

    ReplyDelete
  8. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    Devops Training in Chennai

    ReplyDelete

  9. This blog gives very important info about .Net Thanks for sharing


    Dot Net Online Course Bangalore

    ReplyDelete
  10. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.
    AWS Online Training

    ReplyDelete
  11. Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.

    selenium training in chennai
    aws training in chennai

    ReplyDelete
  12. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 

    java training in chennai | java training in bangalore

    java training in tambaram | java training in velachery

    java training in omr | oracle training in chennai

    ReplyDelete
  13. A universal message I suppose, not giving up is the formula for success I think. Some things take longer than others to accomplish, so people must understand that they should have their eyes on the goal, and that should keep them motivated to see it out til the end.

    python training in velachery
    python training institute in chennai


    ReplyDelete
  14. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
    Python training in pune
    AWS Training in chennai
    Python course in chennai

    ReplyDelete
  15. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

    Selenium Training in Bangalore | Best Selenium Training in Bangalore

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    ReplyDelete
  16. Anyhow I am here now and would just like to say thanks a lot for a tremendous post and an all-round exciting blog (I also love the theme/design),
    safety course in chennai

    ReplyDelete
  17. Awesome..You have clearly explained.it is very simple to understand.it's very useful for me to know about new things..Keep posting.Thank You...
    aws online training
    aws training in hyderabad
    amazon web services(AWS) online training
    amazon web services(AWS) training online

    ReplyDelete
  18. I get several your blog! We are a team of volunteers and starting a new initiative in a community in the same niche.
    safety course in chennai

    ReplyDelete

  19. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    AWS Training in Chennai
    Data Science Training in Chennai
    Python Training in Chennai
    RPA Training in Chennai
    Digital Marketing Training in Chennai

    ReplyDelete
  20. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    Android Training in Chennai | Best Android Training in Chennai
    Selenium Training in Chennai | Best Selenium Training in chennai
    Devops Training in Chennai | Best Devops Training in Chennai

    ReplyDelete
  21. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  22. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  23. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    Microsoft Azure online training
    Selenium online training
    Java online training
    uipath online training
    Python online training


    ReplyDelete
  24. Such an informative and helpful, Thank you for sharing this wonderful post.


    Data Science

    ReplyDelete
  25. Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.





    DATA SCIENCE COURSE MALAYSIA

    ReplyDelete
  26. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article. I appreciate your post and look forward tomorrow.data science course in singapore

    ReplyDelete

  27. I really have to search sites with relevant information on given topic and provide them to teacher our opinion and the article. I appreciate your post and look forward tomorrow.data science course in singapore

    ReplyDelete
  28. Great information on given topic and provide them to teacher our opinion and the article. I appreciate your post and look forward tomorrow.data science course in singapore

    ReplyDelete
  29. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    Great post, Thanks for sharing.

    ReplyDelete

  30. Its as if you had a great grasp on the subject matter, but you forgot to include your readers. Perhaps you should think about this from more than one angle.
    Data Science Courses

    ReplyDelete
  31. Very interesting, Wish to see much more like this. Thanks for sharing your information!
    Data science
    Learn Machine

    ReplyDelete
  32. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!
    data analytics course malaysia

    ReplyDelete
  33. i am really happy to say it’s an interesting post to read . I learn new information from your article , you are doing a great job . Keep it up and This paragraph gives clear idea for the new viewers of blogging.
    One Machine Learning
    One data science
    www.bexteranutrition.com
    www.digital marketingfront.com
    designing info.in
    www.https://www.hindimei.net

    ReplyDelete
  34. i am really happy to say it’s an interesting post to read . I learn new information from your article , you are doing a great job . Keep it up and This paragraph gives clear idea for the new viewers of blogging.
    One Machine Learning
    One data science
    www.bexteranutrition.com
    www.digital marketingfront.com
    designing info.in
    www.https://www.hindimei.net

    ReplyDelete
  35. Post is very useful. Thank you, this useful information.

    Learn Best Informatica Training in Bangalore from Experts. Softgen Infotech offers the Best Informatica Training in Bangalore.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  36. This is the first & best article to make me satisfied by presenting good content. I feel so happy and delighted. Thank you so much for this article.




    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery




    ReplyDelete
  37. I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read !! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.Data Science Institute in Bangalore

    ReplyDelete
  38. We are urgently in need of Organs Donors, Kidney donors,Female Eggs,Kidney donors Amount: $500.000.00 Dollars
    Female Eggs Amount: $500,000.00 Dollars
    WHATSAP: +91 91082 56518
    Email: : customercareunitplc@gmail.com
    Please share this post.

    ReplyDelete
  39. Gone through this wonderful coures called Salesforce Certification Training in Dallas who are offering fully practical course, who parent is Salesforce Training in USA and they have students at Salesforce Training classes in Canada institutes.Gone through this wonderful coures called Salesforce Certification Training in Dallas who are offering fully practical course, who parent is Salesforce Training in USA and they have students at Salesforce Training classes in Canada institutes.

    ReplyDelete
  40. This comment has been removed by the author.

    ReplyDelete
  41. Such an excellent and interesting blog, do post like this more with more information, this was very useful.   Salesforce Training India    

    ReplyDelete
  42. This comment has been removed by the author.

    ReplyDelete
  43. This comment has been removed by the author.

    ReplyDelete
  44. This comment has been removed by the author.

    ReplyDelete
  45. This comment has been removed by the author.

    ReplyDelete
  46. I feel really happy to have seen your web page and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Data Science Training in Hyderabad

    ReplyDelete
  47. Those guidelines additionally worked to become a good way to
    recognize that other people online have the identical fervor like mine
    to grasp great deal more around this condition.
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  48. You may wish to comment on the blog's order system. It's splendid you can talk. Your blog audit will have your visitors swelling. I was really happy to find this blog. I wanted to thank you for the excellent reading!!data science course

    ReplyDelete
  49. Amazing post found to be very impressive while going through this post. Thanks for sharing and keep posting such an informative content.

    360DigiTMG Python Course

    ReplyDelete
  50. This comment has been removed by the author.

    ReplyDelete
  51. May I simply just say what a relief to discover someone that actually knows what they are talking about online. You actually know how to bring an issue to light and make it important. A lot more people ought to look at this and understand this side of the story. It's surprising you aren't more popular given that you definitely possess the gift.
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev
    mbilaldev

    ReplyDelete
  52. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome. I will instantly grab your rss feed to stay informed of any updates you make and as well take the advantage to share some latest information about

    CREDIT CARD HACK SOFTWARE which many are not yet informed, of the recent technology.

    Thank so much for the great job.

    ReplyDelete
  53. Nice work... Much obliged for sharing this stunning and educative blog entry!
    ai training in noida

    ReplyDelete
  54. https://zulqarnainbharwana.com/laurence-fox/

    ReplyDelete

  55. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works ExcelR Data Analytics Course

    ReplyDelete
  56. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
    Data Science courses

    ReplyDelete
  57. I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge.
    data scientist training and placement

    ReplyDelete
  58. Hope you guys are well and healthy during this time. Guys if you want to utilise your time to do something interesting then we are here for you. Our institution is offering CS executive classes and free CSEET classes only for you guys. So contact us or visit our website at https://uniqueacademyforcommerce.com/

    ReplyDelete

  59. Python training in Chennai | Infycle Technoogies:

    Are you looking for Python training in Chennai? Then, Infycle Technologies, we will work with you to realize your dream. Infycle Technologies is one of the best big data training institutions in Chennai, providing various big data courses, such as Oracle, Java, AWS, Hadoop, etc., and conducting comprehensive practical training with expert trainers in this field. In addition to training, mock interviews will also be arranged for candidates so that they can face the interview with the best knowledge. Among them, a 100% resettlement guarantee will be obtained here. To get the above text in the real world, please call Infycle Technologies at 7502633633 and get a free demo to learn more

    Data science ith job placemet

    ReplyDelete
  60. Description:
    Don’t miss this Infycle Education feast!! Special menu like updated Java, Python, Big Data, Oracle, AWS, and more than 20 software-related courses. Just get Data Science from the best Data Science Training Institute in Chennai, Infycle Technologies, which helps to recreate your life. It can help to change your boring job into a pep-up energetic job because, in this feast, you can top-up your knowledge. To enjoy this Data Science training in Chennai, just make a call to 7502633633.
    Best software training in chennai

    ReplyDelete
  61. Don't Waste Your Time Checking USD TO INR FORECAST Every Day! Get The Most Accurate Exchange Rate For The USD TO INR FORECAST With Our Original Universal Currency Converter.

    ReplyDelete
  62. The USD TO INR FORECASTConverter Is Updated Every 15 Minutes. You Can Set It To Alert You Whenever The Rate Changes.

    ReplyDelete
  63. I want to say thanks to you. I have bookmark your site for future updates.
    data scientist certification malaysiaa


    ReplyDelete
  64. XM REVIEW If You Are A Beginner, Check Out Our Guide On How To Open An Account With XM. They Offer Copy Trading Where You Can Copy The Trades Of Successful Traders.

    ReplyDelete
  65. I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end.
    Data Analytics Courses In Pune

    ReplyDelete
  66. Nice blog and informative content. Keep up this awesome work in your further blogs. Thank you. If you want to become a data scientist, then follow the below link.
    Data Science Training and Placements in Hyderabad

    ReplyDelete
  67. This is an awesome motivating article.I am practically satisfied with your great work.You put truly extremely supportive data. Keep it up. Continue blogging. Hoping to perusing your next post
    cyber security training malaysia

    ReplyDelete
  68. Enroll yourself in the Data Science training online program and reach the epitome of success
    data science course in malaysia

    ReplyDelete
  69. Thanks for posting the best information the blog is very helpful.
    Jewellery Billing Software
    Jewellery Billing Software

    ReplyDelete
  70. thanks for sharing informative post like this
    Jewellery ERP Software Dubai
    Jewellery ERP Software Dubai

    ReplyDelete