Can't Update Values In Microsoft Access - vb.net

I have a problem that when I try updating data the the program doesn't save it in the database.
This is the current code:
Dim y As Byte = Convert.ToByte(lblID.Text) - 1
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("dset").Rows(y).Item(1) = txtname.Text
ds.Tables("dset").Rows(y).Item(2) = txtsubm.Text & "/" & txtsubd.Text & "/" & txtsuby.Text
ds.Tables("dset").Rows(y).Item(3) = txtexpm.Text & "/" & txtexpd.Text & "/" & txtexpy.Text
ds.Tables("dset").Rows(y).Item(5) = txtnotes.Text
If MdComboBox1.SelectedItem = "A" Then
ds.Tables("dset").Rows(y).Item(4) = "A"
ElseIf MdComboBox1.SelectedItem = "B" Then
Else
MdAlertBox1.Text = "Please Select A Class The Class Box"
MdAlertBox1.Visible = True
End If
MdAlertBox1.Text = "Data Sucessfully Updated !"
MdAlertBox1.kind = MDAlertBox._Kind.Success
MdAlertBox1.Visible = True
getinfo.Start()
updatedata.Stop()
And the declared variables:
Dim conn As New OleDb.OleDbConnection
Dim DbProv As String = "PROVIDER=microsoft.ACE.OLEDB.12.0;"
Dim Src As String = " data source = c:\users\kingo\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\BigGymDB.accdb"
Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet

Put a debug.print to see the values you are passing to the Database. Like this:
ds.Tables("dset").Rows(y).Item(2) = txtsubm.Text & "/" & txtsubd.Text & "/" & txtsuby.Text
ds.Tables("dset").Rows(y).Item(3) = txtexpm.Text & "/" & txtexpd.Text & "/" & txtexpy.Text
ds.Tables("dset").Rows(y).Item(5) = txtnotes.Text
'your code ---^
debug.print txtname.Text; txtsubm.Text & "/" & txtsubd.Text & "/" & txtsuby.Text;
debug.print txtnotes.Text; txtexpm.Text & "/" & txtexpd.Text & "/" & txtexpy.Text
'your code ---v
If MdComboBox1.SelectedItem = "A" Then
ds.Tables("dset").Rows(y).Item(4) = "A"
ElseIf MdComboBox1.SelectedItem = "B" Then
Then in two lines in the Immdiate Window, you should see whether these txtsub.Text and the other 3 inputs actually have something.

Related

SSIS Create and Attaching file to the email

I've 2 sqlreaders and both should loop through it and second sqlreader data should create a table and inserting into the excel sheet.
Lets say
I've sqlreader and sqlreader1
sqlreader has some data which is required to get sqlreader1
I'm able to get sqlreader1 data as I expected
but once I loaded data to datatable, I'm loosing sqlreader1 and not able to see any info in sqlreader1
If SqlDataReader.HasRows Then
Do While SqlDataReader.Read()
Dim ExcelFileName As String = Dts.Variables("User::FolderPath").Value.ToString() + "Accrual_Input_Summary_Q" + SqlDataReader.Item("Accrual_Quarter").ToString() + " FY-" + SqlDataReader.Item("Accrual_FY").ToString() + ".xlsx"
'Dim recipientName As String = SqlDataReader.Item("recipient_name").ToString()
'Dim recipientEmail As String = SqlDataReader.Item("Recipient_Email").ToString()
Try
If System.IO.File.Exists(ExcelFileName) = True Then
System.IO.File.Delete(ExcelFileName)
End If
Dim SqlCmd1 As New SqlCommand("[POT].[PROC_POT_Accrual_Reminder_Summary]", SqlCon)
SqlCmd1.CommandType = CommandType.StoredProcedure
SqlCmd1.CommandTimeout = 0
SqlCmd1.Parameters.AddWithValue("#Qtype", "Accrual_Summary")
SqlCmd1.Parameters.AddWithValue("#Accrual_Created_By_Email", SqlDataReader.Item("Recipient_Email").ToString())
Dim SqlDataReader1 As SqlDataReader = SqlCmd1.ExecuteReader()
' connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" &
'"Data Source=" & ExcelFileName &
'";Extended Properties=Excel 12.0 Xml;HDR=YES;"
If SqlDataReader1.HasRows Then
While SqlDataReader1.Read()
Dim connectionString As String
Dim excelConnection As OleDbConnection
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ExcelFileName & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
excelConnection = New OleDbConnection(connectionString)
Dim Excel_OLE_Cmd As OleDbCommand = New OleDbCommand()
Dim recipientName As String = SqlDataReader1.Item("Created_By_Name").ToString()
Dim recipientEmail As String = SqlDataReader1.Item("CostCenterAnalyst").ToString()
Dim costCenterOwner As String = SqlDataReader1.Item("CostCenterOwner").ToString()
Dim TableColumns As String = ""
Dim dtCustomers As New DataTable("sqlDataTable")
**dtCustomers.Load(SqlDataReader1)**
For Each column As DataColumn In dtCustomers.Columns
TableColumns += column.ToString() & "],["
Next
TableColumns = ("[" & TableColumns.Replace(",", " Text,").TrimEnd(","c))
TableColumns = TableColumns.Remove(TableColumns.Length - 2)
excelConnection.ConnectionString = connectionString
excelConnection.Open()
Excel_OLE_Cmd.Connection = excelConnection
Excel_OLE_Cmd.CommandText = "Create table " & "Sheet1" & " (" & TableColumns & ")"
Excel_OLE_Cmd.ExecuteNonQuery()
Dim sqlCommandInsert As String = ""
Dim sqlCommandValue As String = ""
For Each dataColumn As DataColumn In dtCustomers.Columns
sqlCommandValue += dataColumn.ToString() & "],["
Next
sqlCommandValue = "[" & sqlCommandValue.TrimEnd(","c)
sqlCommandValue = sqlCommandValue.Remove(sqlCommandValue.Length - 2)
sqlCommandInsert = "INSERT into " & "Sheet1" & "(" & sqlCommandValue & ") VALUES("
Dim columnCount As Integer = dtCustomers.Columns.Count
For Each row As DataRow In dtCustomers.Rows
Dim columnvalues As String = ""
For i As Integer = 0 To columnCount - 1
Dim index As Integer = dtCustomers.Rows.IndexOf(row)
columnvalues += "'" & dtCustomers.Rows(index).ItemArray(i).ToString() & "',"
Next
columnvalues = columnvalues.TrimEnd(","c)
Dim command As String = sqlCommandInsert & columnvalues & ")"
Excel_OLE_Cmd.CommandText = command
Excel_OLE_Cmd.ExecuteNonQuery()
Next
excelConnection.Close()
StrMailBody_Inner = " Hello Cost Center Analyst (" & recipientName & "), <br/><br/> PFA accrual inputs for the current quarter. Please review & take appropriate action click <a href='http://podashboarddev/' target='_blank'>here</a>.<br/><br/>"
StrMailBody_Inner = StrMailBody_Inner + " <u>Note</u><br/>"
StrMailBody_Inner = StrMailBody_Inner + " <ol>"
StrMailBody_Inner = StrMailBody_Inner + " <li>The accrual inputs provided doesn't interface with SAP. You will still need to post the necessary accrual JV.</li>"
StrMailBody_Inner = StrMailBody_Inner + " <li>CCA can leverage the tool for accrual tracking.</li>"
StrMailBody_Inner = StrMailBody_Inner + " </ol>"
Using myMessage As New MailMessage(Dts.Variables("email_from").Value, recipientEmail)
Dim copy As MailAddress = New MailAddress(costCenterOwner)
myMessage.CC.Add(copy)
myMessage.IsBodyHtml = True
myMessage.Subject = Dts.Variables("email_subject").Value
myMessage.Body = StrMailBody.ToString().Replace("$$$$Mail_Body$$$$", StrMailBody_Inner)
myMessage.Priority = System.Net.Mail.MailPriority.High
myMessage.Attachments.Add(New Attachment(ExcelFileName))
mySmtpClient = New SmtpClient("mailserver.amat.com")
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
'mySmtpClient.Send(myMessage)
Dim str_SQL As String
str_SQL = "INSERT INTO [POT].[tbl_POT_Open_PO_Accrual_Reminder_History] ([Recipient_Email], [Reminder_Type]) VALUES ('" + SqlDataReader.Item("recipient_email").ToString() + "', 'Accrual_Summary');"
Dim SqlCmdHist As New SqlCommand(str_SQL, SqlCon)
SqlCmdHist.CommandType = CommandType.Text
SqlCmdHist.CommandTimeout = 0
SqlCmdHist.ExecuteNonQuery()
SqlCmdHist.Dispose()
End Using
End While
SqlDataReader1.Close()
End If
Once I load data to Datatable using this
dtCustomers.Load(SqlDataReader1)
before load data:
after load data:
I'm missing the sqlreader1 and i'm unable to loop through it.
it is giving Invalid attempt to call Read when reader is closed.
Note: I've enabled MultipleActiveResultSets
can we do any other things that we can do to resolve this issue

VB.NET ComboBox selected item not remains effect than 2 times

I have a VB windows form application that has 02 ComboBox that provide newname input for a renaming file event. The first combobox provide prefix for new name comprise items (aa, bb, cc,... can add more through keydown button click event), the other combobox provide main name comprise items (XX, YY, ZZ,.. can also add more through keydown button click event). When I select "aa" from the first combobox, "XX" from the other then fire the rename event, the new file name should be "aa - XX", if file "aa - XX" has already existed then add "1" to the last as "aa - XX 1" and so on and if no item selected in prefix combobox the newname just be "XX" and increment. I get the old file name through a system openfiledialog. My code for rename as follows:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim var As String, prfix As String
var = ComboBox1.Text
prfix = ComboBox2.Text
If ComboBox2.Text = Nothing Then
If File.Exists(n & "\" & var & extn) = False Then
My.Computer.FileSystem.RenameFile(OpenFD.FileName, var & extn)
Else
Dim i As Integer = 1
Dim newfn As String = var & " " & i & extn
Dim m As String = n & "\" & newfn
While File.Exists(m)
newfn = var & " " & i & extn
m = n & "\" & newfn
i += 1
End While
My.Computer.FileSystem.RenameFile(OpenFD.FileName, newfn)
End If
Else
If File.Exists(n & "\" & prfix & " - " & var & extn) = False Then
My.Computer.FileSystem.RenameFile(OpenFD.FileName, prfix & " - " & var & extn)
Else
Dim j As Integer = 1
Dim newfn1 As String = prfix & " - " & var & " " & j & extn
Dim k As String = n & "\" & newfn1
While File.Exists(k)
newfn1 = var & " " & j & extn
k = n & "\" & newfn1
j += 1
End While
My.Computer.FileSystem.RenameFile(OpenFD.FileName, newfn1)
End If
End If
MessageBox.Show("Select a next file")
End Sub
My code run well 2 times. After I select "aa" and "XX" and leave it to rename, first result is "aa - XX", the second result is "aa - XX 1" but the third result is "XX", the forth is "XX 1" and then incrementing so on while the result should be "aa - XX 2" and next increment. I don't understand why combobox1 still effective but combobox2 as Nothing after no re-selecting the item in both comboboxes (2 times). I'm very new with VB so any advice should be much appreciated. Thanks.
In your lower Else block, you were incorrectly building up the file name.
You build up the first "newfn1" with:
Dim newfn1 As String = prfix & " - " & var & " " & j & extn
But then below, you used:
newfn1 = var & " " & j & extn
Notice the missing prefix and dash parts at the beginning.
Here's the full corrected version:
Dim j As Integer = 1
Dim newfn1 As String = prfix & " - " & var & " " & j & extn
Dim k As String = Path.Combine(n, newfn1)
While File.Exists(k)
j = j + 1
newfn1 = prfix & " - " & var & " " & j & extn
k = Path.Combine(n, newfn1)
End While
My.Computer.FileSystem.RenameFile(OpenFD.FileName, newfn1)
I'm a little confused by your explanation but if I understand correctly this should help,
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
CreateFile()
End Sub
Private BasePath As String = "" 'TODO
Private Ext As String = "txt"
Private Sub CreateFile()
If ComboBox1.SelectedIndex < 0 OrElse
ComboBox2.SelectedIndex < 0 OrElse
ComboBox1.SelectedItem.ToString = "" OrElse
ComboBox2.SelectedItem.ToString = "" Then
'error message
Exit Sub
End If
Dim fileName As String = String.Format("{0}-{1}.{2}",
ComboBox1.SelectedItem.ToString,
ComboBox2.SelectedItem.ToString,
Ext)
fileName = IO.Path.Combine(BasePath, fileName)
Dim ct As Integer = 1
Do While IO.File.Exists(fileName)
fileName = String.Format("{0}-{1}{3}.{2}",
ComboBox1.SelectedItem.ToString,
ComboBox2.SelectedItem.ToString,
Ext,
ct)
fileName = IO.Path.Combine(BasePath, fileName)
ct += 1
Loop
Dim fs As IO.FileStream = IO.File.Create(fileName)
fs.Close()
fs.Dispose()
End Sub

VBA/Access: How to stop "You... FORM to be active window"

I want to be able to tell IF a form is the active window.
It seems simply invoking that method produces an error. I guess I could catch that error and run with it, but it's a backwards way of doing it.
Screen.ActiveForm.Name
This needs a form to be active. If I am breaking any rules of stackOverflow please be kind and remind me as I am new to forum.
Screen.parent, screen.activeControl, etc. What if VBA editor is open, as often it is?
Function CStatus(strStatus, ByRef intType As Integer, Optional ByRef erNo, Optional erMsg, Optional strDatum)
'pXname = "CStatus"
'pXStack = Left(pXStack, 500) & ">" & pXname
'Updates and manages the status bar
Dim strPreamble As String, strOut As String, strForm As String, strComment As String, strSQL As String, strPxStack As String, strCErrStack As String
Dim intColor As Double
Dim intPreLen As Integer
'On Error GoTo err_hand
'Color Codes
'12632256 = Lt Grey
'33023 = Orange
'65280 = Green
'16744576 = Steel Grey
'Define "Constants"
intPreLen = 350 'Length of previous message cache
'** Fix missings
If (IsMissing(strDatum) = True) Then strDatum = "[N/A]"
'** Other inits
strWindow = Screen.Parent.Name
strForm = Screen.ActiveForm.Name
'** intDebug ' Minimum Level of to report to status
'bEcho = True 'Whether to echo to status
intColor = errNoColor(intType)
'Error-level idiot explanations
strComment = "0"
If IsMissing(erNo) Then erNo = 0
If (IsNull(erMsg) = False) Then
If IsMissing(erMsg) = False Then strComment = erMsg
End If
strComment = errorTree(erNo)
strPreamble = Left(strPreamble, intPreLen) & "..."
strErrStack = Left(strErrStack, intPreLen) & " > " & pXname & ":" & intType
strCErrStack = strErrStack
reS:
If ((strForm = "finvmain") Or (strForm = "fclips")) Then Screen.ActiveForm.timeStatusUpdated = Now() 'Small field keeps time
If bEcho = True Then
strPxStack = ""
strCErrStack = "" 'Internal error stack
End If
strOut = Now() & " " & intType & " (" & strType & "): " & erNo & " " & strCErrStack & " >> " & strComment & " / " & strStatus & " [" & strDatum & "] .. " & strPreamble
If bEcho = True Then
If (strForm = "fInvMain") Then Screen.ActiveForm.txtStatus2 = Screen.ActiveForm.txtStatus 'Added second window to show previous message
Screen.ActiveForm.txtStatus = strOut
End If
Screen.ActiveForm.txtStatus.ForeColor = intColor
If strForm = "fInvMain" Then strTag = Screen.ActiveForm.Controls("txttag").value
'***Event Log
If erNo = "" Then erNo = 0
If IsMissing(erMsg) = True Then erMsg = ""
If IsMissing(strDatum) = True Then strDatum = ""
If Len(strPreamble) < 2 Then strPreamble = "[None]"
'Fixxed - Syntax Error for Some Odd Reason! Apr 27th
If ((strTag = Empty) And (strForm = "fInvMain")) Then strTag = Screen.ActiveForm.txtTag 'Attempt to add tag# to entry
strStatus = cleanString(strStatus)
strDatum = cleanString(strDatum)
strComment = cleanString(strComment)
strSQL = "INSERT INTO tEvents(txtdate, myerrno, interrno, myerrmsg, interrmsg, txtform, stack, process, Datum, idLink) VALUES ('" & Now() & "','" & intType & "','" & erNo & "','" & strStatus & "','" & strComment & "','" & strForm & "','" & strErrStack & "','" & pXname & "','" & strDatum & "','" & strTag & "');"
CurrentDb.Execute strSQL, dbFailOnError
Exit Function
err_hand:
If Err.Number = 2475 Then
bEcho = False
Resume reS
Else: MsgBox "555: CStatus Internal Error, Turn off error handling to view"
End If
End Function
I need a boolean true or false IF form is active. If it isn't, I can't put stuff into a textbox in that.
To determine if a particular form is open then set focus to form:
If CurrentProject.AllForms("finvmain").IsLoaded
strForm = "finvmain"
Elseif CurrentProject.AllForms("fclips").IsLoaded Then
strForm = "fclips"
End If
If strForm <> "" Then DoCmd.SelectObject acForm, strForm

Weird issue with saving to SQL database

I have managed to create a connection to the database and am able to save information to it from my form, the form contains 22 textboxes, a save and another exit button.
I have set the form to retrieve data in the form_load. I have used the "UPDATE" SQL command on the save button and it does save the data on all 22 textboxes (all textboxes are linked to their separate columns). But only one record will be needed that is why I did not use the "INSERT" command.
The problem arises when I click the save button, all (19) textboxes are saved but when I retrieve the text (by reloading the form), each of the 20, 21, 22 textboxes (only) the text of the 20th textbox keeps on moving tho the next textbox e.g. 20>21>22>20>21>22 is interchanged amongst themselves.
Please help me (I googled this but found nothing on this) and please tell me why this is happening.
The code is below:
Dim sqCon As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;Database=MegaDatabase;Integrated Security=SSPI")
Dim sqCmd As New SqlClient.SqlCommand
sqCmd.Connection = sqCon
Dim DatabaseErrorMsg As String = "Unable to save the details. Please contact the program developers."
Dim DatabaseErrorTitle As String = "Database Editing Error"
Dim DatabaseDoneSave As String = "New records made/updated successfully"
Dim CompNmtxtS As String
Dim TrdNmtxtS As String
Dim ComRegtxtS As String
Dim WTNmtxtS As String
Dim VRegtxtS As String
Dim TextBox1S As String
Dim ComPosttxtS As String
Dim StrAddrtxtS As String
Dim ComCitytxtS As String
Dim ComCounttxtS As String
Dim RegAddrtxtS As String
Dim ComZiptxtS As String
Dim RepTeltxtS As String
Dim ComFaxtxtS As String
Dim RepCelltxtS As String
Dim W_URLtxtS As String
Dim EWebtxtS As String
Dim BankNametxtS As String
Dim BankBranchtxtS As String
Dim BraCodetxtS As String
Dim BankAcctxtS As String
Dim TextBox2S As String
CompNmtxtS = CompNmtxt.Text
TrdNmtxtS = TrdNmtxt.Text
ComRegtxtS = ComRegtxt.Text
WTNmtxtS = WTNmtxt.Text
VRegtxtS = VRegtxt.Text
TextBox1S = TextBox1.Text
ComPosttxtS = ComPosttxt.Text
StrAddrtxtS = StrAddrtxt.Text
ComCitytxtS = ComCitytxt.Text
ComCounttxtS = ComCounttxt.Text
RegAddrtxtS = RegAddrtxt.Text
ComZiptxtS = ComZiptxt.Text
RepTeltxtS = RepTeltxt.Text
ComFaxtxtS = ComFaxtxt.Text
RepCelltxtS = RepCelltxt.Text
ComFaxtxtS = ComFaxtxt.Text
W_URLtxtS = W_URLtxt.Text
EWebtxtS = EWebtxt.Text
BankNametxtS = BankNametxt.Text
BankBranchtxtS = BankBranchtxt.Text
BraCodetxtS = BraCodetxt.Text
BankAcctxtS = BankAcctxt.Text
TextBox2S = TextBox2.Text
Try
'*NOTE: UPDATE function will only UPDATE the fields when there is already something in there, as it cannot work for the INSERT command
'Format for UPDATE command: USE DatabaseName; UPDATE Tablename SET ColumnName = '" & declared string name & "'"
sqCmd.CommandText = ("USE MegaDatabase; UPDATE CompDetails SET CompName = '" & CompNmtxtS & "', TradeName = '" & TrdNmtxtS & "', CompReg = '" & ComRegtxtS & "', WTnum = '" & WTNmtxtS & "', VATregNo = '" & VRegtxtS & "', TaxPeriod = '" & TextBox1S & "', CompPostalAddr = '" & ComPosttxtS & "', CompPhysAddr = '" & StrAddrtxtS & "', CompCity = '" & ComCitytxtS & "', CompCountry = '" & ComCounttxtS & "', CompProvince = '" & RegAddrtxtS & "', CompZip = '" & ComZiptxtS & "', CompTel = '" & RepTeltxtS & "', CompFax = '" & ComFaxtxtS & "', CompCell = '" & RepCelltxtS & "', CompWebsite = '" & W_URLtxtS & "', CompEmail = '" & EWebtxtS & "', CompBankName = '" & BankNametxtS & "', CompBranchName = '" & BankBranchtxtS & "', CurrentTaxTable = '" & TextBox2S & "', CompBranchCode = '" & BraCodetxtS & "', CompAccNo = '" & BankAcctxtS & "'")
sqCon.Open()
sqCmd.ExecuteNonQuery()
sqCon.Close()
Catch ex As Exception
MessageBox.Show(DatabaseErrorMsg, DatabaseErrorTitle, MessageBoxButtons.OK)
Finally
Me.Close()
frmMDImainform.MainMenuStrip.Enabled = True
MessageBox.Show(DatabaseDoneSave, "Done Saving...", MessageBoxButtons.OK)
End Try
For the loading part:
Try
sqCmd.CommandText = "SELECT TOP 1 [CompName],[TradeName],[CompReg],[WTnum],[VATregNo],[TaxPeriod],[CompPostalAddr],[CompPhysAddr],[CompCity],[CompCountry],[CompProvince],[CompZip],[CompTel],[CompFax],[CompCell],[CompWebsite],[CompEmail],[CompBankName],[CompBranchName],[CurrentTaxTable],[CompBranchCode],[CompAccNo] FROM [MegaDatabase].[dbo].[CompDetails]"
sqCon.Open()
sqRdr = sqCmd.ExecuteReader()
Catch ex As Exception
End Try
Do While sqRdr.Read() 'No need for VbTab and Vb crlf
CompNmtxt.Text = CompNmtxt.Text & sqRdr.GetValue(0)
TrdNmtxt.Text = TrdNmtxt.Text & sqRdr.GetValue(1)
ComRegtxt.Text = ComRegtxt.Text & sqRdr.GetValue(2)
WTNmtxt.Text = WTNmtxt.Text & sqRdr.GetValue(3)
VRegtxt.Text = VRegtxt.Text & sqRdr.GetValue(4)
TextBox1.Text = TextBox1.Text & sqRdr.GetValue(5)
ComPosttxt.Text = ComPosttxt.Text & sqRdr.GetValue(6)
StrAddrtxt.Text = StrAddrtxt.Text & sqRdr.GetValue(7)
ComCitytxt.Text = ComCitytxt.Text & sqRdr.GetValue(8)
ComCounttxt.Text = ComCounttxt.Text & sqRdr.GetValue(9)
RegAddrtxt.Text = RegAddrtxt.Text & sqRdr.GetValue(10)
ComZiptxt.Text = ComZiptxt.Text & sqRdr.GetValue(11)
RepTeltxt.Text = RepTeltxt.Text & sqRdr.GetValue(12)
ComFaxtxt.Text = ComFaxtxt.Text & sqRdr.GetValue(13)
RepCelltxt.Text = RepCelltxt.Text & sqRdr.GetValue(14)
W_URLtxt.Text = W_URLtxt.Text & sqRdr.GetValue(15)
EWebtxt.Text = EWebtxt.Text & sqRdr.GetValue(16)
BankNametxt.Text = BankNametxt.Text & sqRdr.GetValue(17)
BankBranchtxt.Text = BankBranchtxt.Text & sqRdr.GetValue(18)
BraCodetxt.Text = BraCodetxt.Text & sqRdr.GetValue(19)
BankAcctxt.Text = BankAcctxt.Text & sqRdr.GetValue(20)
TextBox2.Text = TextBox2.Text & sqRdr.GetValue(21)
Loop
Thanks for reading
You have a mixup in the order of your columns in your query vs. accessing the columns by index when reading your resultset:
In your query column #21 (last column, zero-based index) is [CompAccNo] but when reading you assign column #21 to TextBox2.Text.
I'd suggest you rather access your columns by name when reading:
CompNmtxt.Text = CompNmtxt.Text & sqRdr.GetValue("CompName")
TrdNmtxt.Text = TrdNmtxt.Text & sqRdr.GetValue("TradeName")
ComRegtxt.Text = ComRegtxt.Text & sqRdr.GetValue("CompReg")
'...
Another point: Get rid of creating your update query by concatenating user input - use Command Parameters instead!

How to Add Text to a VB.NET RadioButtonList

I'm dynamically creating a RadioButtonList and can't figure out how to add additional text to show up under the radio button.
My basic code is as follows and I want sURL to show up under each resultant radio button.
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim iLocationID As Integer = ds.Tables(0).Rows(i).Item("LocationID")
Dim sStreet As String = ds.Tables(0).Rows(i).Item("AddressStreet")
Dim sCity As String = ds.Tables(0).Rows(i).Item("AddressCity")
Dim sState As String = ds.Tables(0).Rows(i).Item("AddressState")
Dim sZip As String = ds.Tables(0).Rows(i).Item("AddressPostalCode")
Dim sName as String = ds.Tables(0).Rows(i).Item("Name")
Dim dsContact As New DataSet
Dim sURL As String = ""
sURL = "<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" & sStreet & "+" & sState & "+" & sZip & "' target='_blank'>" & sStreet & " " & sCity & " " & sState & ", " & sZip & "</a>"
Dim dDistance As Decimal = Math.Round(ds.Tables(0).Rows(i).Item("Distance"), 1)
Dim sDistance As String
If dDistance > 1 Then
sDistance = dDistance & " Miles Away"
Else
sDistance = dDistance & " Mile Away"
End If
sURL += " " & sDistance
sURL += " Phone: " & sContactPhone
rblVendorLocations.Items.Add(New ListItem(sName, iLocationID))
Next
The first parameter to the ListItem constructor is the text to show beside the radio button, if you want that to be sURL then pass that rather than sName.
You can also pass html as this parameter if you want to style it in some particular way e.g.
ListDeliveryFrequency.Items.Add( _
New ListItem("<div>" + sName +"</div> <div>" + sUrl + "</div>", _
iLocationID))