vb.net mysql javascript
-
Public Sub FetchDataByName(customerName As String)
' Show debugging message
MessageBox.Show("FetchDataByName called with Name: " & customerName)' Replace with your actual MySQL connection details Dim connectionString As String = "Server=localhost;Port=3306;Database=MyData;Uid=asmgssl;Pwd=0786;" Dim query As String = "SELECT \* FROM customer WHERE cname = @cname" Try Using connection As New MySqlConnection(connectionString) connection.Open() Using command As New MySqlCommand(query, connection) command.Parameters.AddWithValue("@cname", customerName) Using reader As MySqlDataReader = command.ExecuteReader() ' Process query result If reader.Read() Then ' Example: Retrieve data and show in message box Dim customerId As Integer = reader.GetInt32("id") Dim customerAddress As String = reader.GetString("address") MessageBox.Show($"Customer ID: {customerId}, Address: {customerAddress}") Else MessageBox.Show("No data found for Name: " & customerName) End If End Using End Using End Using Catch ex As Exception MessageBox.Show("Error fetching data: " & ex.Message) End Try End Sub Private Sub LoadHtmlContent() ' Define the HTML content Dim html As String = "" & "" & "" & "Test Page" & "" & "function FetchDataByName() {" & " if (window.external && typeof window.external.FetchDataByName === 'function') {" & " var customerName = document.getElementById('inputName').value;" & " console.log('Fetching data for customer name: ' + customerName);" & " window.external.FetchDataByName(customerName);" & " } else {" & " console.error('window.external.FetchDataByName is not available.');" & " }" & "}" &
</x-turndown>
-
Public Sub FetchDataByName(customerName As String)
' Show debugging message
MessageBox.Show("FetchDataByName called with Name: " & customerName)' Replace with your actual MySQL connection details Dim connectionString As String = "Server=localhost;Port=3306;Database=MyData;Uid=asmgssl;Pwd=0786;" Dim query As String = "SELECT \* FROM customer WHERE cname = @cname" Try Using connection As New MySqlConnection(connectionString) connection.Open() Using command As New MySqlCommand(query, connection) command.Parameters.AddWithValue("@cname", customerName) Using reader As MySqlDataReader = command.ExecuteReader() ' Process query result If reader.Read() Then ' Example: Retrieve data and show in message box Dim customerId As Integer = reader.GetInt32("id") Dim customerAddress As String = reader.GetString("address") MessageBox.Show($"Customer ID: {customerId}, Address: {customerAddress}") Else MessageBox.Show("No data found for Name: " & customerName) End If End Using End Using End Using Catch ex As Exception MessageBox.Show("Error fetching data: " & ex.Message) End Try End Sub Private Sub LoadHtmlContent() ' Define the HTML content Dim html As String = "" & "" & "" & "Test Page" & "" & "function FetchDataByName() {" & " if (window.external && typeof window.external.FetchDataByName === 'function') {" & " var customerName = document.getElementById('inputName').value;" & " console.log('Fetching data for customer name: ' + customerName);" & " window.external.FetchDataByName(customerName);" & " } else {" & " console.error('window.external.FetchDataByName is not available.');" & " }" & "}" &
</x-turndown>
AMRO DAMMAM wrote:
not fetch data
Did you debug your code?
-
Public Sub FetchDataByName(customerName As String)
' Show debugging message
MessageBox.Show("FetchDataByName called with Name: " & customerName)' Replace with your actual MySQL connection details Dim connectionString As String = "Server=localhost;Port=3306;Database=MyData;Uid=asmgssl;Pwd=0786;" Dim query As String = "SELECT \* FROM customer WHERE cname = @cname" Try Using connection As New MySqlConnection(connectionString) connection.Open() Using command As New MySqlCommand(query, connection) command.Parameters.AddWithValue("@cname", customerName) Using reader As MySqlDataReader = command.ExecuteReader() ' Process query result If reader.Read() Then ' Example: Retrieve data and show in message box Dim customerId As Integer = reader.GetInt32("id") Dim customerAddress As String = reader.GetString("address") MessageBox.Show($"Customer ID: {customerId}, Address: {customerAddress}") Else MessageBox.Show("No data found for Name: " & customerName) End If End Using End Using End Using Catch ex As Exception MessageBox.Show("Error fetching data: " & ex.Message) End Try End Sub Private Sub LoadHtmlContent() ' Define the HTML content Dim html As String = "" & "" & "" & "Test Page" & "" & "function FetchDataByName() {" & " if (window.external && typeof window.external.FetchDataByName === 'function') {" & " var customerName = document.getElementById('inputName').value;" & " console.log('Fetching data for customer name: ' + customerName);" & " window.external.FetchDataByName(customerName);" & " } else {" & " console.error('window.external.FetchDataByName is not available.');" & " }" & "}" &
</x-turndown>
You have not given sufficient information to diagnose this. "no fetch data" can mean anything at any point in this code. You have a bunch of MessageBox statements which should be showing you the important values, but you don't mention anything at all about what they are saying.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak