Moving between DataGridView rows via code and show through textboxes - vb.net

I'm not an experienced programmer and I must have made some misconceptions.
I have two forms, one for the search (FormSearch) and one to show the results (FormMain).
The question is: how can I populate the textboxes with the previous results (click on the btnPrev button) or the next results (click on the btnNext button)?
FormSearch
Imports System.Data.SqlClient
Public Class FormSearch
Private Sub btnsearch_Click(sender As Object, e As EventArgs) Handles btnsearch.Click
Dim con As New SqlConnection("Data Source=" & Form1.server & "," & Form1.port & "; Initial Catalog=" & Form1.database & "; User Id=" & Form1.txtUsername.Text & "; Password=" & Form1.txtPassword.Text & ";")
Dim cmd As New SqlCommand("select * FROM dbo.customers;", con)
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable
adapter.Fill(table)
DataGridView1.DataSource = table
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
FormMain.TextBox1.Text = row.Cells("Name").Value.ToString
FormMain.TextBox2.Text = row.Cells("Surname").Value.ToString
FormMain.TextBox3.Text = row.Cells("Age").Value.ToString
Me.Hide()
FormMain.Show()
End If
End Sub
End Class
FormMain
Public Class FormMain
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
FormSearch.Show()
Me.Hide()
End Sub
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev.Click
'Show prev result
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
'Show next result
End Sub
End Class

Try this:
1) Apply the code below in FormMain
Public Class FormMain
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
FormSearch.Show()
Me.Hide()
End Sub
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev.Click
BS.Position = BS.Position - 1
DisplayRecords()
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
BS.Position = BS.Position + 1
DisplayRecords()
End Sub
End Class
2) Apply the code below in FormSearch
Imports System.Data.SqlClient
Public Class FormSearch
Private Sub btnsearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim con As New SqlConnection("Data Source=" & Form1.server & "," & Form1.port & "; Initial Catalog=" & Form1.database & "; User Id=" & Form1.txtUsername.Text & "; Password=" & Form1.txtPassword.Text & ";")
Dim adapter As New SqlDataAdapter("select * FROM [dbo.customers]", con)
adapter.Fill(DS, "myTableNane")
BS.DataSource = DS
BS.DataMember = "myTableNane"
DataGridView1.DataSource = BS
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 Then
BS.Position = e.RowIndex
Me.Hide()
FormMain.Show()
End If
End Sub
End Class
2) Create a Module and place the below code.
Module Module1
Public DS As New DataSet
Public WithEvents BS As New BindingSource
Sub DisplayRecords(Optional ByVal table As String = "myTableNane")
FormMain.TextBox1.Text = DS.Tables(table).Rows(BS.Position)("Name").ToString
FormMain.TextBox2.Text = DS.Tables(table).Rows(BS.Position)("Surename").ToString
FormMain.TextBox3.Text = DS.Tables(table).Rows(BS.Position)("Age").ToString
End Sub
End Module
Hope you find it helpful and solved your problem.
Moiyd

Related

Search to DataGridView ( showing record) selected record print vb.net

This is my code but it prints all records. I want to search a record and print crystalreport.
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'
Me.Patient_tblTableAdapter.Fill(Me.DoctorDataSet.patient_tbl)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PatienttblBindingSource.Filter = "(Convert(ID,'System.String') LIKE '" & TextBox1.Text & "%')"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rpt As New CrystalReport1
rpt.SetDataSource(DoctorDataSet)
Form2.CrystalReportViewer1.ReportSource = rpt
Form2.ShowDialog()
End Sub
End Class
try to use '*' instead '%' in like statement :
PatienttblBindingSource.Filter = "(Convert(ID,'System.String') LIKE '" & TextBox1.Text & "*')"

System.Data.OleDb.OleDbException: 'Syntax error in FROM clause.'

It keeps telling me syntax error in FROM clause. Any thought on fixing this code? I followed the tutorial 100%, somehow this error keeps happen. Also I'm using VS2019 and Microsoft Access 365. This is visual basic .net form.
Public Class Form1
Dim cmdlog As OleDbCommand
Dim drlog As OleDbDataReader
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs) Handles Clear.Click
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Btn_Login_Click(sender As Object, e As EventArgs) Handles Btn_Login.Click
Dim conn As New OleDbConnection("Provider= Microsoft.ACE.OLEDB.12.0;Data Source= C:\Users\Jane\Documents\MYSJ GA\MySJ GA\bin\Debug\Mysejahtera1.accdb")
Dim cmdlog As OleDbCommand = New OleDbCommand("Select * from user log in where [user_ID]='" & textBoxuser.Text & "' and [user_pw]='" & textBoxpw.Text & "'", conn)
conn.Open()
Dim drlog As OleDbDataReader = cmdlog.ExecuteReader
If drlog.Read() = True Then
Me.Hide()
Form4.Show()
MsgBox("login successfully")
Else
MsgBox("login failed")
End If
End Sub
End Class
I think you should use square brackets in table name:
"Select * from [user log in] where [user_ID]='"

How to update an Access DB from a DataGridView in Visual Basic

I am creating an inventory application which runs off of an Access DB in visual studio, using visual basic. I can populate my data grid view just fine, but when I try to add new information into the data grid view, it does not number correctly and it does not append my database.
I have tried binding and updating using the table adapter.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
CustomersBindingSource.AddNew()
Me.Validate()
Me.CustomersTableAdapter.Update(Me.Database1DataSet.Customers)
Me.CustomersBindingSource.EndEdit()
End Sub
Here is my code:
Public Class Form1
Private Sub enterbtn_Click(sender As Object, e As EventArgs) Handles enterbtn.Click
If username.Text = "Tanner" And password.Text = "bmis365" Then
GroupBox1.Visible = False
Else
MsgBox("Incorrect Username or Password, please try again.")
username.Clear()
password.Clear()
username.Focus()
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.CurrentCell = Nothing
'This line of code loads data into the 'Database1DataSet.Customers' table. You can move, or remove it, as needed.
Me.CustomersTableAdapter.Fill(Me.Database1DataSet.Customers)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'This is where my new info is to be appended into the database, once the button is clicked.
CustomersBindingSource.AddNew()
Me.Validate()
Me.CustomersTableAdapter.Update(Me.Database1DataSet.Customers)
Me.CustomersBindingSource.EndEdit()
End Sub
Private Sub searchbtn_Click(sender As Object, e As EventArgs) Handles searchbtn.Click
'The Following Code is from https://social.msdn.microsoft.com/Forums/vstudio/en-US/36c54726-4f49-4e15-9597-7b201ec13ae7/search-in-datagrid-using-textbox-vbnet-without-data-connectivity?forum=vbgeneral
For Each row As DataGridViewRow In DataGridView2.Rows
For Each cell As DataGridViewCell In row.Cells
If Not IsNothing(cell.Value) Then
If cell.Value.ToString.StartsWith(searchbar.Text, StringComparison.InvariantCultureIgnoreCase) Then
cell.Selected = True
DataGridView2.CurrentCell = DataGridView2.SelectedCells(0)
End If
End If
Next
Next
End Sub
End Class
My output initially has 3 rows(numbered 1, 2, and 3) but any that are added through the application have the numbers -1, -2, -3 and so on. Also, when I close the program and restart it, my original rows (1, 2, and 3) are still there from when I entered them in the DB file, but any that were added through my application are gone.
Here is one way to do an Update, as well as a few other common SQL manipulations/operations.
Imports System.Data.SqlClient
Public Class Form1
Dim sCommand As SqlCommand
Dim sAdapter As SqlDataAdapter
Dim sBuilder As SqlCommandBuilder
Dim sDs As DataSet
Dim sTable As DataTable
Private Sub load_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles load_btn.Click
Dim connectionString As String = "Data Source=.;Initial Catalog=pubs;Integrated Security=True"
Dim sql As String = "SELECT * FROM Stores"
Dim connection As New SqlConnection(connectionString)
connection.Open()
sCommand = New SqlCommand(sql, connection)
sAdapter = New SqlDataAdapter(sCommand)
sBuilder = New SqlCommandBuilder(sAdapter)
sDs = New DataSet()
sAdapter.Fill(sDs, "Stores")
sTable = sDs.Tables("Stores")
connection.Close()
DataGridView1.DataSource = sDs.Tables("Stores")
DataGridView1.ReadOnly = True
save_btn.Enabled = False
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
End Sub
Private Sub new_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles new_btn.Click
DataGridView1.[ReadOnly] = False
save_btn.Enabled = True
new_btn.Enabled = False
delete_btn.Enabled = False
End Sub
Private Sub delete_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delete_btn.Click
If MessageBox.Show("Do you want to delete this row ?", "Delete", MessageBoxButtons.YesNo) = DialogResult.Yes Then
DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(0).Index)
sAdapter.Update(sTable)
End If
End Sub
Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
sAdapter.Update(sTable)
DataGridView1.[ReadOnly] = True
save_btn.Enabled = False
new_btn.Enabled = True
delete_btn.Enabled = True
End Sub
End Class

TextBoxes using parent control BindingContexts don't display data value

I am having a problem when I try to bind to text boxes to separate BindingContexts (via a container control such as a GroupBox). The textboxes don't display the bound value. (This example is based on the bindingcontext documentation here)
Here is the code:
Dim ds As New DataSet1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
BindControls()
GetData()
End Sub
Private Sub BindControls()
Dim bcG1 As New BindingContext()
Dim bcG2 As New BindingContext()
GroupBox1.BindingContext = bcG1
'GroupBox2.BindingContext = bcG2
TextBox1.DataBindings.Add("Text", ds, "Orders.OrderKey") ' groupbox1
TextBox2.DataBindings.Add("Text", ds, "Orders.OrderKey") ' groupbox2
TextBox3.DataBindings.Add("Text", ds, "Orders.OrderKey") ' form
End Sub
When I run the form Textbox3 (at the form level) and textbox2 (in GroupBox2) are synchronized as expected and TextBox2 displays the value of OrderKey. However, Textbox1 (in GroupBox1) does not show any values. I have determined that GroupBox1 is indeed using a separate BindingContext and position commands do move to new rows independent of the form. If I comment out setting GroupBox1's BindingContext it behaves as Texbox2, synchronized at the form level. If I uncomment setting Groupbox2's BindingContext, it behaves as Textbox1, unsynchronized but doesn't display any values in the textbox.
Can anybody see what I'm missing?
Here is the full code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim ds As New DataSet1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
BindControls()
GetData()
End Sub
Private Sub BindControls()
Dim bcG1 As New BindingContext()
Dim bcG2 As New BindingContext()
GroupBox1.BindingContext = bcG1
'GroupBox2.BindingContext = bcG2
TextBox1.DataBindings.Add("Text", ds, "Orders.OrderKey") ' groupbox1
TextBox2.DataBindings.Add("Text", ds, "Orders.OrderKey") ' groupbox2
TextBox3.DataBindings.Add("Text", ds, "Orders.OrderKey") ' form
End Sub
' ** groupbox1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GroupBox1.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(GroupBox1.BindingContext(ds, "Orders").Current, DataRowView)
TextBox5.Text = drv("OrderKey")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
GroupBox1.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(GroupBox1.BindingContext(ds, "Orders").Current, DataRowView)
TextBox5.Text = drv("OrderKey")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
GroupBox2.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(GroupBox2.BindingContext(ds, "Orders").Current, DataRowView)
TextBox6.Text = drv("OrderKey")
End Sub
' ** groupbox2
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
GroupBox2.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(GroupBox2.BindingContext(ds, "Orders").Current, DataRowView)
TextBox6.Text = drv("OrderKey")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Me.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(Me.BindingContext(ds, "Orders").Current, DataRowView)
TextBox4.Text = drv("OrderKey")
End Sub
' ** Form
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Me.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(Me.BindingContext(ds, "Orders").Current, DataRowView)
TextBox4.Text = drv("OrderKey")
End Sub
Private Sub GetDataButton_Click(sender As Object, e As EventArgs) Handles GetDataButton.Click
GetData()
End Sub
Public Sub GetData()
ds.Clear()
Dim ota As New DataSet1TableAdapters.OrdersTableAdapter
ota.Adapter.SelectCommand = New SqlCommand("SELECT OrderKey, CustomerFK, OrderDate, DeliveryMethod, Special_Instr, " & _
"TotalOrderAmount " & _
"FROM Orders ", ota.Connection)
ota.Adapter.Fill(ds)
End Sub
End Class
Microsoft declined to address the bug report at this time but I did find that I could use BindingSources to accomplish what I was trying to do. Important note: To set the filter the BindingSource.DataSource property needs to be set to a new DataView. By default it uses the DataTable's default view so setting the filter on one instance of the BindingSource sets it for the other. The DataSource assignment would be similar to this:
BindingSource1.DataSource = New DataView(DataSource1.DataTable1)
Here is the revised code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1BindingSource
Dim ds As New DataSet1
Dim bsForm As BindingSource
Dim bsG1 As BindingSource
Dim bsG2 As BindingSource
Dim BindingSource1 As BindingSource
Private _OcConnectionString As String
Public Property OcConnectionString() As String
Get
Return _OcConnectionString
End Get
Set(ByVal value As String)
_OcConnectionString = value
End Set
End Property
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
BindControls()
GetData()
End Sub
Public Sub New(strConnection As String)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
OcConnectionString = strConnection
BindControls()
GetData()
End Sub
Private Sub BindControls()
bsForm = New BindingSource
bsG1 = New BindingSource
bsG2 = New BindingSource
bsForm.DataSource = ds
bsG1.DataSource = ds
bsG2.DataSource = ds
bsForm.DataMember = "Orders"
bsG1.DataMember = "Orders"
bsG2.DataMember = "Orders"
'BindingSource1 = New BindingSource(ds, "Orders")
BindingSource1 = New BindingSource
BindingSource1.DataSource = ds
BindingSource1.DataMember = "Orders"
Me.DataGridView1.DataSource = BindingSource1
TextBox1.DataBindings.Add("Text", bsG1, "OrderKey") ' groupbox1
TextBox2.DataBindings.Add("Text", bsG2, "OrderKey") ' groupbox2
TextBox3.DataBindings.Add("Text", BindingSource1, "OrderKey") ' form
TextBox8.DataBindings.Add("Text", BindingSource1, "OrderKey") ' Groupbox3
End Sub
' ** groupbox1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
bsG1.MovePrevious()
'GroupBox1.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(bsG1.Current, DataRowView)
TextBox5.Text = drv("OrderKey")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
bsG1.MoveNext()
'GroupBox1.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(bsG1.Current, DataRowView)
TextBox5.Text = drv("OrderKey")
End Sub
' ** groupbox2
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
bsG2.MovePrevious()
'GroupBox2.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(bsG2.Current, DataRowView)
TextBox6.Text = drv("OrderKey")
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
bsG2.MoveNext()
'GroupBox2.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(bsG2.Current, DataRowView)
TextBox6.Text = drv("OrderKey")
End Sub
'** form level
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
bsForm.MovePrevious()
'Me.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(bsForm.Current, DataRowView)
TextBox4.Text = drv("OrderKey")
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
bsForm.MoveNext()
'Me.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(bsForm.Current, DataRowView)
TextBox4.Text = drv("OrderKey")
End Sub
'** Groupbox3
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
bsForm.MovePrevious()
'GroupBox3.BindingContext(ds, "Orders").Position -= 1
Dim drv As DataRowView = CType(bsForm.Current, DataRowView)
TextBox8.Text = drv("OrderKey")
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
bsForm.MoveNext()
'GroupBox3.BindingContext(ds, "Orders").Position += 1
Dim drv As DataRowView = CType(bsForm.Current, DataRowView)
TextBox8.Text = drv("OrderKey")
End Sub
Private Sub GetDataButton_Click(sender As Object, e As EventArgs) Handles GetDataButton.Click
GetData()
End Sub
Public Sub GetData()
Try
Dim ota As New DataSet1TableAdapters.OrdersTableAdapter
If OcConnectionString IsNot Nothing Then
ota.Connection.ConnectionString = OcConnectionString
End If
ds.Clear()
ota.Adapter.SelectCommand = New SqlCommand("SELECT OrderKey, CustomerFK, OrderDate, DeliveryMethod, Special_Instr, " & _
"TotalOrderAmount " & _
"FROM Orders ", ota.Connection)
ota.Adapter.Fill(ds)
Catch exp As Exception
MsgBox(exp.Message)
End Try
End Sub
End Class
Carl

Throw New NotImplementedException - VB

I'm making an application that manages the inputs and outputs of a company's customers as well as the creation of the same, however when I "submit" the form of the creation of a new customer to me the following error:
"Throw New NotImplementedException"
I leave here my code, so they can help me.
FORM1.vb
Public Class Form1
Private Property cnt As Object
<SerializableAttribute> _
'<ComVisibleAttribute(True)> _
Public Class NotImplementedException _
'Inherits SystemException
End Class
Private Sub TabPage1_Click(sender As Object, e As EventArgs)
Dim cnt As New OleDb.OleDbConnection
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
TabControl1.SelectedTab = TabPage2
End Sub
Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'cnt.ConnectionString = "Provinder=Microsoft.Jet.Oledb.40; Data Source=" & Application.StartupPath & "\bdtesteentradas.mdb"
'TODO: This line of code loads data into the 'BdtesteentradasDataSet.empresa' table. You can move, or remove it, as needed.
Me.EmpresaTableAdapter.Fill(Me.BdtesteentradasDataSet.empresa)
End Sub
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs) Handles FillByToolStripButton.Click
Try
Me.EmpresaTableAdapter.FillBy(Me.BdtesteentradasDataSet.empresa)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Me.EmpresaBindingSource.Filter = "nif ='" & TextBox1.Text & "'"
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox2.Text = ""
TextBox3.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox5.Text = ""
TextBox4.Text = ""
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Dim cnt As New OleDb.OleDbCommand
If Not ConnectionState.Open Then
End If
Cmd.Connection = cnt()
Cmd.CommandText = "INSERT INTO empresa (NIF, Empresa, nCliente, Distrito, NomeContacto, ApelidoContacto, Funcao" &
"VALUES(" & Me.TextBox6.Text & ")"
'Cmd.ExecuteNonQuery()
MsgBox("Dados inseridos.")
End Sub
Cmd.vb
Class Cmd
Shared Property CommandText As String
Shared Property Connection As Object
Shared Sub ExecuteNonQuery()
Throw New NotImplementedException
End Sub
End Class
Error message
Already a big thank you
You got error on your "cmd" variable and "fixed it" this way:
Didn't you? This generated the file Cmd.vb for you.
That is not what you want. Remove Cmd.vb from you project an try this:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'You want to check, what the State of *your* connection is
If Not cnt.State = ConnectionState.Open Then
End If
'Create a Command-Object from the Connection
Using cmd = cnt.CreateCommand()
cmd.CommandText = "INSERT INTO empresa (NIF, Empresa, nCliente, Distrito, NomeContacto, ApelidoContacto, Funcao" &
"VALUES(" & Me.TextBox6.Text & ")"
cmd.ExecuteNonQuery()
MsgBox("Dados inseridos.")
End Using
End Sub