Connect to Remote SQL database via Code
How do I code for a connection to a remote SQL server/database file, then add a new row of information and close the connection?
Alternately, how do I connect to the database to view the data in a datagrid, then close the connection?
Purposes; a database that takes data, and stores it for use later for reporting and quality purposes. I would use the New Data Source wizard, but it won't connect to remote databases, and I'm already in over my head...here is an example of the code for the program that inputs the data to the data base:
Public Class frmMain
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Table1TableAdapter.Fill(Me.Tracker1DataSet.Tabl e1)
'TODO: This line of code loads data into the 'Tracker1DataSet.Table1' table. You can move, or remove it, as needed.
Private Sub cboReasonCode_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboReasonCode.Leave
If cboReasonCode.Text = "" Then
MsgBox("Please Enter a Reason Code for to Continue.")
Me.cboReasonCode.Focus()
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Close()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtCSAID.Text = ""
cboOU.Text = ""
cboOU.SelectedItem = vbNullString
cboReasonCode.Text = ""
cboReasonCode.SelectedItem = vbNullString
dtpDate.Value = Now
txtCustID.Text = ""
txtNo.Text = ""
txtNotes.Text = ""
ckbCSNet.CheckState = CheckState.Unchecked
ckbBlurbDB.CheckState = CheckState.Unchecked
ckbWizard.CheckState = CheckState.Unchecked
ckbWebsite.CheckState = CheckState.Unchecked
ckbHelpPages.CheckState = CheckState.Unchecked
ckbKnowledgeCenter.CheckState = CheckState.Unchecked
ckbEmail.CheckState = CheckState.Unchecked
ckbTechCSNet.CheckState = CheckState.Unchecked
ckbSharepoint.CheckState = CheckState.Unchecked
ckbHandouts.CheckState = CheckState.Unchecked
ckbInquiry.CheckState = CheckState.Unchecked
ckbEscalation.CheckState = CheckState.Unchecked
ckbEscAppYes.CheckState = CheckState.Unchecked
ckbEscAppNo.CheckState = CheckState.Unchecked
txtCSAID.Focus()
End Sub
Private Sub txtCSAID_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCSAID.Leave
dtpDate.Value = Now
If txtCSAID.Text = "" Then
MsgBox("Please Enter a CSA Log In to Continue.")
Me.txtCSAID.Focus()
ElseIf txtCSAID.Text.Length < 2 Then
MsgBox("Please Enter a Valid CSA Log In to Continue.")
Me.txtCSAID.Focus()
End If
End Sub
Private Sub txtCustID_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCustID.Leave
If txtCustID.Text = "" Then
MsgBox("Please Enter a Customer ID to Continue.")
Me.txtCustID.Focus()
ElseIf txtCustID.Text.Length < 4 Then
MsgBox("Please Enter a Valid Customer ID to Continue.")
Me.txtCustID.Focus()
End If
End Sub
Private Sub btnSubmit_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim strWebsite As String
Dim strHelpPages As String
Dim strCSNet As String
Dim strBlurbDB As String
Dim strWizard As String
Dim strKnowCent As String
Dim strEmail As String
Dim strTechCSNet As String
Dim strSharepoint As String
Dim strHandouts As String
Dim strInquiry As String
Dim strEscalation As String
Dim strEscApp As String
If txtCustID.Text = "" Then
MsgBox("Please Enter a Customer ID Before You Submit This Record.")
Me.txtCustID.Focus()
End If
If txtCustID.Text.Length < 4 Then
MsgBox("Please Enter a Valid Customer ID Before You Submit This Record.")
Me.txtCustID.Focus()
End If
If txtCSAID.Text = "" Then
MsgBox("Please Enter a CSA Log In Before You Submit This Record.")
Me.txtCSAID.Focus()
End If
If txtCSAID.Text.Length < 2 Then
MsgBox("Please Enter a Valid CSA Log In Before You Submit This Record.")
Me.txtCSAID.Focus()
End If
If cboReasonCode.Text = "" Then
MsgBox("Please Enter a Reason Code Before You Submit This Record.")
Me.cboReasonCode.Focus()
End If
If cboOU.Text = "" Then
MsgBox("Please Enter an OU Before You Submit This Record.")
Me.cboOU.Focus()
End If
If Not txtOrder.Text = "" Then
If Not txtOrder.Text.Length = 19 Then
MsgBox("Please Enter the Dashes in the Order ID.")
Me.txtOrder.Focus()
End If
End If
If txtOrder.Text = "" Then
txtOrder.Text = "N/A"
End If
If ckbCSNet.CheckState = CheckState.Checked Then
strCSNet = "Y"
ElseIf ckbCSNet.CheckState = CheckState.Unchecked Then
strCSNet = "U"
End If
If ckbBlurbDB.CheckState = CheckState.Checked Then
strBlurbDB = "Y"
ElseIf ckbBlurbDB.CheckState = CheckState.Unchecked Then
strBlurbDB = "U"
End If
If ckbWizard.CheckState = CheckState.Checked Then
strWizard = "Y"
ElseIf ckbWizard.CheckState = CheckState.Unchecked Then
strWizard = "U"
End If
If ckbWebsite.CheckState = CheckState.Checked Then
strWebsite = "Y"
ElseIf ckbWebsite.CheckState = CheckState.Unchecked Then
strWebsite = "U"
End If
If ckbHelpPages.CheckState = CheckState.Checked Then
strHelpPages = "Y"
ElseIf ckbHelpPages.CheckState = CheckState.Unchecked Then
strHelpPages = "U"
End If
If ckbKnowledgeCenter.CheckState = CheckState.Checked Then
strKnowCent = "Y"
ElseIf ckbKnowledgeCenter.CheckState = CheckState.Unchecked Then
strKnowCent = "U"
End If
If ckbEmail.CheckState = CheckState.Checked Then
strEmail = "Y"
ElseIf ckbEmail.CheckState = CheckState.Unchecked Then
strEmail = "U"
End If
If ckbTechCSNet.CheckState = CheckState.Checked Then
strTechCSNet = "Y"
ElseIf ckbTechCSNet.CheckState = CheckState.Unchecked Then
strTechCSNet = "U"
End If
If ckbSharepoint.CheckState = CheckState.Checked Then
strSharepoint = "Y"
ElseIf ckbSharepoint.CheckState = CheckState.Unchecked Then
strSharepoint = "U"
End If
If ckbHandouts.CheckState = CheckState.Checked Then
strHandouts = "Y"
ElseIf ckbHandouts.CheckState = CheckState.Unchecked Then
strHandouts = "U"
End If
If ckbInquiry.CheckState = CheckState.Checked Then
strInquiry = "Y"
ElseIf ckbInquiry.CheckState = CheckState.Unchecked Then
strInquiry = "U"
End If
If ckbEscalation.CheckState = CheckState.Checked Then
strEscalation = "Y"
ElseIf ckbEscalation.CheckState = CheckState.Unchecked Then
strEscalation = "U"
End If
If ckbEscAppYes.CheckState = CheckState.Checked Then
strEscApp = "Y"
ElseIf ckbEscAppNo.CheckState = CheckState.Checked Then
strEscApp = "N"
Else
strEscApp = "U"
End If
If strInquiry = "U" Then
If strEscalation = "U" Then
MsgBox("Please Enter The CSA Contact Reason")
Me.ckbInquiry.Focus()
End If
End If
If txtNo.Text = "" Then
txtNo.Text = "N/A"
End If
If txtNotes.Text = "" Then
txtNotes.Text = "N/A"
End If
Me.Validate()
Me.Table1TableAdapter.Insert(frmLogIn.txtLeadID.Te xt, txtCSAID.Text, txtCustID.Text, txtOrder.Text, cboOU.Text, cboReasonCode.Text, dtpDate.Value, strCSNet, strBlurbDB, strWizard, strHelpPages, strKnowCent, strWebsite, strEmail, strTechCSNet, strSharepoint, strHandouts, strInquiry, strEscalation, strEscApp, txtNo.Text, txtNotes.Text)
MsgBox("Update successful")
txtCSAID.Text = ""
cboOU.Text = ""
cboOU.SelectedItem = vbNullString
cboReasonCode.Text = ""
cboReasonCode.SelectedItem = vbNullString
dtpDate.Value = Now
txtNo.Text = ""
txtNotes.Text = ""
txtCustID.Text = ""
txtOrder.Text = ""
ckbCSNet.CheckState = CheckState.Unchecked
ckbBlurbDB.CheckState = CheckState.Unchecked
ckbWizard.CheckState = CheckState.Unchecked
ckbWebsite.CheckState = CheckState.Unchecked
ckbHelpPages.CheckState = CheckState.Unchecked
ckbKnowledgeCenter.CheckState = CheckState.Unchecked
ckbEmail.CheckState = CheckState.Unchecked
ckbTechCSNet.CheckState = CheckState.Unchecked
ckbSharepoint.CheckState = CheckState.Unchecked
ckbHandouts.CheckState = CheckState.Unchecked
ckbInquiry.CheckState = CheckState.Unchecked
ckbEscalation.CheckState = CheckState.Unchecked
ckbEscAppYes.CheckState = CheckState.Unchecked
ckbEscAppNo.CheckState = CheckState.Unchecked
btnExit.Focus()
End Sub
Private Sub cboOU_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboOU.Leave
If cboOU.Text = "" Then
MsgBox("Please Enter an OU to continue.")
Me.cboOU.Focus()
End If
End Sub
Private Sub btnEndOfShift_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
frmSubmit.Show()
End Sub
Private Sub txtOrder_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtOrder.Leave
Dim string1 As String
Dim string2 As String
Dim string3 As String
Dim string4 As String
If Not txtOrder.Text = "" Then
If txtOrder.Text.Length < 17 Then
MsgBox("Please Enter the Complete Order ID")
txtOrder.Focus()
ElseIf txtOrder.Text.Length = 17 Then
string1 = txtOrder.Text.Remove(3, 14)
string2 = txtOrder.Text.Remove(0, 3)
string3 = string2.Remove(6, 7)
string4 = txtOrder.Text.Remove(0, 10)
txtOrder.Text = string1 & "-" & string3 & "-" & string4
End If
End If
End Sub
Private Sub ckbEscalation_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckbEscalation.Leave
If ckbInquiry.CheckState = CheckState.Unchecked Then
If ckbEscalation.CheckState = CheckState.Unchecked Then
MsgBox("Please Enter The CSA Contact Reason")
Me.ckbInquiry.Focus()
End If
End If
End Sub
Private Sub ckbEscAppNo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckbEscAppNo.Leave
If ckbEscalation.CheckState = CheckState.Checked Then
If ckbEscAppYes.CheckState = CheckState.Unchecked Then
If ckbEscAppNo.CheckState = CheckState.Unchecked Then
MsgBox("You Indicated This Contact is an Escalation, Please Indicate if This is an Appropriate Escalation.")
ckbEscAppYes.Focus()
End If
End If
End If
End Sub
Private Sub txtNo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNo.Leave
If ckbEscAppNo.CheckState = CheckState.Checked Then
If txtNo.Text = "" Then
MsgBox("Please Indicate Why This Escalation is Not Appropriate.")
txtNo.Focus()
End If
End If
End Sub
Private Sub btnExit_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
End Class
|