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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dileep Kumar PatelPosted Apr 3, 2014, 6:13 AM
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.
Munesh SharmaPosted Apr 3, 2014, 6:11 AM
selvi subramanianPosted Apr 3, 2014, 6:06 AM
Munesh SharmaPosted Apr 3, 2014, 2:48 AM
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();
}
Dileep Kumar PatelPosted Apr 3, 2014, 2:27 AM
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