update data from a dataset to the database - vb.net

the remove button actually removes the data from the dataset but when i restart the program it just reappears, tried with "Me.testTableAdapter.Fill(Me.testDataSet.test)", searched a lot and still didnt find anything. any help appreciated!
here is the code:
Imports System
Imports System.Data.OleDb
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
Dim con As OleDbConnection
Dim com As OleDbCommand
Dim txtconnesione As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: questa riga di codice carica i dati nella tabella 'testDataSet.test'. È possibile spostarla o rimuoverla se necessario.
Me.INATableAdapter.Fill(Me.testDataSet.test)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
con = New OleDbConnection(txtconnesione)
com = New OleDbCommand("INSERT INTO INA (CODICE,Interno,esterno,altezza) VALUES(#CODICE,#Interno,#esterno,#altezza)", con)
con.Open()
com.Parameters.AddWithValue("#CODICE", txtcodice.Text)
com.Parameters.AddWithValue("#Interno", txtinterno.Text)
com.Parameters.AddWithValue("#esterno", txtesterno.Text)
com.Parameters.AddWithValue("#altezza", txtaltezza.Text)
com.ExecuteNonQuery()
MsgBox("New Record")
Me.testTableAdapter.Fill(Me.testDataSet.test)
con.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each row As DataGridViewRow In DataGridView1.SelectedRows
DataGridView1.Rows.Remove(row)
testDataSet.test.DataSet.AcceptChanges()
Next
End Sub
End Class

Related

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]='"

System.Data.OleDb.OleDbException: 'Data type mismatch in criteria expression.' VB. Net

Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection
Dim sql As String
Dim cmd As OleDbCommand
Dim odr As OleDbDataReader
Dim dt As New DataTable
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\e_alq\OneDrive\Desktop\a3\test.mdb"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
con.Open()
da = New OleDbDataAdapter("Select * from test where basicsalary > 1 ", con)
ds.Tables.Add(dt)
DataGridView1.DataSource = dt.DefaultView
da.Fill(dt)
ds.Tables.Clear()
con.Close()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
End Sub
End Class

Add new row into `DataGridView` and enter data from `TableAdapter` in another form

I am trying to add new row of data in the DataGridView that is located in Form4. The data is to be entered in the Form3 into TableAdapter that is bound with DataGridView.
On the Form4 I have a button that opens Form3 and it suppose to add new rows into DatagridView but seems like it is not doing it.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Form3.Show()
Form4.DbTableDataGridView.Rows.Add() 'this is not executed?
End Sub
On the Form3 there is a TableAdapter that suppose to fill in new added rows in the DbTableDataGridView and then saves the changes. Something like:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form4.DbTableDataGridView.Rows.Add(Me.DbTableTableAdapter)
End Sub
This works fine.
Public Class Form4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form3.ShowDialog()
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form4.DataGridView1.Rows.Add("Add Something here")
End Sub
End Class
Does the data in your datagridview is from database?
You can have a Public Sub in your Form4 to show the records.
Example:
Dim cn As New SqlConnection("your connection string here")
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim dt As New DataTable
Public Sub ShowRecord()
cn.Open()
With cmd
.Connection = cn
.CommandText = "Your command text here"
End With
da.SelectCommand = cmd
dt.Clear()
da.Fill(dt)
dataGridView1.DataSource = dt
cn.Close()
End Sub
In your Form3:
you can save the data in the database then call the sub in form4 like
form4.ShowRecord()
This is just a simple example though

Vb.net hyperlink Dataview and listing between price range

I am working on a assignment in which I have to use VB.net and Access database in order to make a bookstore. One of the requirements is that I have to make a table with book titles and customer names with a hyperlink on the title and customer name which will redirect them to a new page. I have the table working, but I am not able to add a hyperlink to one of the columns in the table. Also there is a searching feature where I have to print all the books between a price range (ex. $20 < price <= $30) I have the radio buttons setup but I am not able to do the actual searching and get good values. My code is below:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class CustomerSearching
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RadioButton1.Visible = False
RadioButton2.Visible = False
RadioButton3.Visible = False
RadioButton4.Visible = False
RadioButton5.Visible = False
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=" + Server.MapPath("~/bookstore.accdb"))
conn.Open()
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Response.Redirect("Customer.aspx")
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OleDb.12.0;Data Source=" + Server.MapPath("~/bookstore.accdb"))
RadioButton1.Visible = True
RadioButton2.Visible = True
RadioButton3.Visible = True
RadioButton4.Visible = True
RadioButton5.Visible = True
If (RadioButton1.Checked) Then
conn.Open()
Dim sql As String = "SELECT * FROM books WHERE price < $10.00"
Dim dbcomm As New OleDb.OleDbCommand(sql, conn)
Dim dbread = dbcomm.ExecuteReader()
bookSearching.DataSource = dbread
bookSearching.DataBind()
dbread.Close()
conn.Close()
End If
End Sub
Protected Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
End Sub
End Class
For the hyperlink I used the vb option to design and dragged a sqlDataSource and a gridview and linked the two together with my bookstore.accdb file. You're help is much appreciated. Thanks a lot.

VB.NET Remove Item in ComboBox after placing in ListBox

How can I remove item in comboBox after
I choose it and put into listBox.
Here's my code. Please help me.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class frmAdvancePayment
Private Sub frmAdvancePayment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lstBillNum.Items.Clear()
Dim connection_string As String = "Data Source=.\sqlexpress;Initial Catalog=CreditAndCollection;Integrated Security=True"
Dim connection As New SqlConnection(connection_string)
connection.Open()
Dim sql As String = "select BillNum from tblBillingSched where Status ='Unpaid'"
Dim da As New SqlDataAdapter(sql, connection_string)
Dim dt As New DataTable
da.Fill(dt)
cmbBillNum.DataSource = dt
cmbBillNum.DisplayMember = "BillNum"
cmbBillNum.ValueMember = "BillNum"
connection.Close()
End Sub
Private Sub btnGet_Click(sender As Object, e As EventArgs) Handles btnGet.Click
lstBillNum.Items.Add(cmbBillNum.SelectedValue)
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
lstBillNum.Items.Clear()
End Sub
End Class
it's what you expect ?
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
Dim index As Integer = ComboBox1.SelectedIndex
ListBox1.Items.Add(ComboBox1.Items(index))
ComboBox1.Items.RemoveAt(index)
End Sub