How to connect asp.net with sql 2005

5 pts.
Tags:
ASP.NET Web applications
SQL Server 2005 connectivity
I am trying to connect asp.net with sql2005 its not responding

I am doing the contact us page where it will upload information to the database . the fields that im having is "Name,Surname,Email,Comments" it does connect but it doesnt up load to a database. Can you give some clues on how to code for that.

Or how to sort it out



Software/Hardware used:
Software

Answer Wiki

Thanks. We'll let you know when a new response is added.

Imports System.Data.SqlClient

Sub SaveData(Name As String, Surname As String, Email As String, Comments As String)
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim intResult As Integer

cn = new SqlConnection(“Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;”)
cmd = new SqlCommand(“”, cn)
cmd.CommandText = “INSERT INTO table_name(name, surname, email, comments) VALUES(‘” & Name & “‘, ‘” & Surname & “‘, ‘” & Email & “‘, ‘” & Comments & “‘)”
Try
cn.Open()
Catch ex As System.Exception
Response.Write(“Error connecting to database: ” & ex.ToString())
Response.End()
End Try

Try
intResult = cmd.ExecuteNonQuery()
Catch ex As System.Exception
Response.Write(“Error saving request: ” & ex.ToString())
Response.End()
End Try

If intResult = 1 Then
Response.Write(“Your request has been sent.”)
Else
Response.Write(“An unknown error has occurred saving your request.”)
End

cn.Close()
End Sub

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following