Question read data from localhost (local pc) to web site in asp.net

prasad kulkarni

Well-known member
Joined
Sep 7, 2009
Messages
62
Programming Experience
1-3
hello friend,

In my asp.net project. Read Button on web form ,when click read button I want to
read record from local sql server and Insert into sql server(on web server) .
if any one knows , then reply me soon
 
Read up on ConnectionStrings, web.config and working with databases in .Net

Be sure to always store the connection string in the web.config file, it'll make changing it when pushing it to production easier.
 
hello friend,

In my asp.net project. Read Button on web form ,when click read button I want to
read record from local sql server and Insert into sql server(on web server) .
if any one knows , then reply me soon

If the web server allows remote connections then it's pretty str8 forward.
You fetch the wanted record from the local DB saving as variable (String or Whatever is appropriate) e.g.
VB.NET:
Dim MyLocalDBValue As String = String.Empty
Dim localconnection As New SqlConnection("YourLocalConnectionStringHere")
Try
      localconnection.Open()
      Dim localcommand As SqlCommand = localconnection.CreateCommand()
      localcommand.CommandText = "SELECT MyValue FROM TableName WHERE <expression>"
      MyLocalDBValue = localcommand.ExecuteScalar()
Catch ex As Exception

Finally
      localconnection.Close()
End Try

Dim remoteconnection As New SqlConnection("YourRemoteConnectionStringHere")
Try
      remoteconnection.Open()
      Dim remotecommand As SqlCommand = remoteconnection.CreateCommand()
      remotecommand.CommandText = "INSERT INTO TableName(MyValue) VALUES('" & MyLocalDBValue & "')"
      remotecommand.ExecuteNonQuery()
Catch ex As Exception

Finally
      remoteconnection.Close()
End Try
 
Back
Top