How to give connection in windows application
how to give sql connection in windows application using VB. we give connection in asp.net using webconfig file. but how to give connection in windows application
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dileep Kumar PatelRank #3,085 · 465 reputationPosted Apr 2, 2014, 10:27 PM EDT
You can use with common class connection with this code:
You can read my blog also for more :
http://www.c-sharpcorner.com/Blogs/9227/types-of-connections-in-Asp-Net-and-ado-net.aspx
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 2, 2014, 10:48 PM EDT
But most of time we give connection in coding part.
i am giving a example of insert values in sql server
Code For Submit
private void Submit_txt_Click(object sender, EventArgs e)
{ //this is the connection with database
string str = "server = MUNESH\\SQL2008R2;Database=datastore;UID=sa;Password=123;";
SqlConnection con = new SqlConnection(str);
string query = "insert into table(ID,Name,Father) values('" + this.id_txt.Text + "','" + this.textBox1.Text + "','" +this.textBox2.Text +"')";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dbr;
try
{
con.Open();
dbr = cmd.ExecuteReader();
// MessageBox.Show("save");
MessageBox.Show("Records saved successfully", "user information");
while (dbr.Read())
{
}
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
id_txt.Text = string.Empty;
con.Close();
}
selvi subramanianRank #2,007 · 723 reputationPosted Apr 3, 2014, 2:06 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 3, 2014, 2:11 AM EDT
Dileep Kumar PatelRank #3,085 · 465 reputationPosted Apr 3, 2014, 2:13 AM EDT
This class you can use whether window application or web application also.This is common class you can use every where also VB code.It will be change only VB code.