Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can i get the connectivity between my front end (c#_ and back end (sql) please ?
Posted
Updated 13-Apr-12 23:36pm
v2

Apart from the answers already given, which will suit the purpose specified in the question, I think this Code Project article
General purpose class to fill DataTable(s) from DataBase and to save DataTable(s) to DataBase using reflection[^]
in which a general purpose class to easily read data from a database and to save data to database is given, may also be helpful.
 
Share this answer
 
Try This Mrunmay...

C#
SqlConnection con = new SqlConnection("server=servername;database=databasename;integrated security=SSPI;MultipleActiveResultSets=true");


On Insert Button Click

C#
SqlCommand cmd = new SqlCommand("insert  into employee values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text  + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Inserted!");


Enjoy Coding
 
Share this answer
 
Comments
VJ Reddy 14-Apr-12 4:51am    
Good answer. 5!
[no name] 14-Apr-12 6:01am    
You have just advised that the OP open himself to SQL injection attacks. He should use a parametrized query instead.
Kuldeep B 14-Apr-12 12:40pm    
Thank U VJ..
You can Add Namespace as system.data.sqlclient
and then you can use
sqlconnection class and sqlcommand class to establish
connection with backend sql server

like this
C#
sqlconnection cn = new sqlconnection();
sqlcommand cm = new sqlcommand();

cn.connectionstring = "your connection string goes here";
cm.connection = cn;
cn.open();
cm.commandtext = "your sql query";
sqldataadapter da = new sqldataadapter(cm);
dataset ds = new dataset();
da.fill(ds);
cn.close();
 
Share this answer
 
v2
Comments
Nelek 14-Apr-12 7:33am    
Added code tags
you can do this with visual studio
Using Visual Studio to find a database connection string[^]

and you can write connection string manually
see http://www.connectionstrings.com/[^]
 
Share this answer
 
Comments
VJ Reddy 14-Apr-12 4:50am    
Good links. 5!
uspatel 14-Apr-12 4:51am    
Thanks Reddy.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900