connection between SQL Server and C#.net
February 8, 2006 by Ashrafur
Hi, This is an easy thing which i have done, i establish connection between SQL Server and C#.net there is a table in my database named login. My code take name and password from textbox and and password field and then check with the databse if name and passwword is correct then redirenc to a new page. |
Here is the sample code: |
|
string connectionString = “Data Source=(local);Initial Catalog=ashraftest;user id=sa;password=faisal”; |
|
string mySelectQuery = “SELECT * from login;”; |
|
SqlConnection myConnection = new SqlConnection(connectionString); |
|
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection); |
|
myConnection.Open(); |
|
SqlDataReader myReader; |
|
myReader = myCommand.ExecuteReader(); |
|
string s1= TextBox1.Text; |
|
string s2= Password1.Value; |
|
while (myReader.Read()) |
|
{ |
|
if((s1.Equals(myReader.GetString(0))) && |
|
(s2.Equals(myReader.GetString(1)))) |
|
Response.Redirect(“loginpage.aspx?name=”+s1); |
|
} |
|
myReader.Close(); |
|
myConnection.Close(); |
|
Posted in C#.net | 20 Comments
information technology
Bio-Technology
send me connection coding on c#.net and sql server
thank you sir i got great help from this actually i just learner of c# and i was searching code for database connectivity
Hi sanjay you are most well come. Happy to be able to help you.
hi . what code is best for connect sql database which is on other server and name of server, database be input .
thanks.
hi . what code is best for connect sql database which is on other server and name of server, database be input .(c#.net)
thanks.
Thanks… I am new learner of C#.net and your code really helped me.
gdgfjhj
please give total discription
Dear Sir,
I just want to query from two tables using JOIN operation in my query but I am using Gridview and Dataset which I can only fill with one table name. Here is the code I want to modify :
String strsql = “Select ad.pid,as.status from ApplicationData ad, ApplicationStatus as WHERE pid=’fcse_1′ ;”;
SqlConnection sqlconn = new sqlConnection(strconnection);
SqlDataAdapter objdataAdapter = new SqlDataAdapter(strsql, sqlconn);
objdataAdapter.Fill(ds,”ApplicationData”);
/* objdataAdapter.Fill(ds,”ApplicationStatus”); If I use this, it gives me error
*/
DataView objdataview = new DataView(ds.Tables[“ApplicationData”]);
dgv.DataSource = objdataview;
dgv.DataBind();
Any kind of help will be highly appreciated:
This is nice explanatoin. i need one more thing how to retrieve the data base and edit that datas in data grid view in front end and it should be saved in back end. my idea is event handling in that data grid view in front end but i dont know the coding write that event coding please send that coding . thank u ashraf
than you sir for this help
Hi, I followed your code for connecting SQL server 2005 and C#.net. But I am getting the an error on “myConnection.Open();”
following is the error message — “Compiler Error Message: CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement”
Could you please help to find out what would be the reason of this error?
hi I want a one simple application code that contain
code for button add,update,delete ,modify
connect to batabase with table.
Check this for more code
http://csharp.net-informations.com/data-providers/csharp-sqlcommand-executenonquery.htm
am doing MCA i wanna sample coding for c#.net with sql server………
how to establish connection with oracle in c#.net
HI neetu ,find the link
http://www.daniweb.com/software-development/csharp/threads/108224/create-database-connection-in-the-c.net
SIR, will u plz help me actullay i am making project in which i ask a question from system and system will give answer to us . i am simply put all the info in database using ntext dataype but how i search this record from database ?? this is my code..
“SqlConnection conn = new SqlConnection(“Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Data.mdf;Integrated Security=True;User Instance=True”);
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter(“SELECT * FROM Agent where question = ” + int.Parse(textBox1.Text), conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt
and format exception is raised due to int.parse