[RESOLVED] Need help connecting between Windows Forms app and SQL Database on website.
I have an application that is ready to put out there that I wrote in VB.NET. Has now been translated to Visual Basic 2010. I'm having difficulties in unfamiliar territory and I seem to have an aversion to digging into it. I'm thinking maybe I should hire some outside help.
I want to communicate between my Windows Forms application and the SQL Database on my website. Want to be able to retrieve information from the SQL database on my website via my application and then also be able to update or change data in the database.
I'm able to open a connection ok but I don't have success after that. If you're interested let me know what your rates are or how much it would be approximately.
Below I was simplifying and just trying to get the data for emailaddress though there a number of other variables in that database. I was using some of the code from the ADO.NET tutorial1 that is provided here at VBForums but translating it to SQL instead of OleDB. There is much I don't know in this area.
Code:
Option Strict On
Imports System.Web.AspNetHostingPermission
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Data.SqlDbType
Imports System.Data.Sql
Imports System.IO
Imports System.Text
Public Class Form1
Dim intCurrentIndex As Integer = 0
Dim conn As New SqlConnection
Dim adec As Decimal
Dim st1 As String = ""
Dim a As Integer = 0
Dim SQL As String
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn.ConnectionString = "Network Library=DBMSSOCN;" & "Data Source=174.120.212.3,1433;" & "Initial Catalog=Database1;" & "User ID=MyUserID;" & "Password=MyPassword"
Try
conn.Open()
da.SelectCommand = New SqlCommand("SELECT EmailAddress FROM Ray Rover Activation")
da.SelectCommand.Connection = conn
MessageBox.Show("Connection Opened Successfully")
DoStuff()
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try
End Sub
Sub DoStuff()
da.UpdateCommand = New SqlCommand("UPDATE Ray Rover Activation SET EmailAddress = @EmailAddress WHERE ActivationID = @ActivationID")
da.SelectCommand = New SqlCommand("SELECT EmailAddress FROM Ray Rover Activation")
da.SelectCommand.Connection = conn
da.UpdateCommand = New SqlCommand("UPDATE Ray Rover Activation SET EmailAddress = @EmailAddress WHERE ActivationID = @ActivationID")
da.UpdateCommand.Connection = conn
da.UpdateCommand.Parameters.Add("@EmailAddress", NVarChar, 99, "EmailAddress")
da.InsertCommand = New SqlCommand("INSERT INTO Ray Rover Activation(EmailAddress) VALUES(@EmailAddress)")
da.InsertCommand.Connection = conn
da.InsertCommand.Parameters.Add("@EmailAddress", NVarChar, 99, "EmailAddress")
da.DeleteCommand = New SqlCommand("DELETE FROM Ray Rover Activation WHERE ActivationID = @ActivationID")
da.DeleteCommand.Connection = conn
da.DeleteCommand.Parameters.Add("@EmailAddress", NVarChar, 99, "EmailAddress")
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then 'Check to see if the table is empty
FillFields()
End If
End Sub
Private Sub FillFields()
TextBoxEmailAddress.Text = ds.Tables(0).Rows(intCurrentIndex).Item("EmailAddress").ToString
End Sub
End Class
Re: Need help connecting between Windows Forms app and SQL Database on website.
I'm making progress on my own now using a couple of books that I have that have been very helpful. Visual Basic 2008 Step by Step and Visual Web Developer 2008 Step by Step so I don't need any outside help. I'm actually glad no one posted to offer help or else I wouldn't have dug into these books. Sometimes not getting help can be very helpful. :)