i used pcode as my primary key which has a datatype of short text
Private Sub RefreshData()
If Not conn.state = ConnectionState.Open Then
conn.Open()
End If
Dim DATA1 As New OleDb.OleDbDataAdapter("SELECT pcode as [Item Code], psup as [Supplier], pcat as [Category], pdescript as [Description], pstock as [In Stock], piprice as [Price], ptprice as [Selling Price], pdate as [Date Added] FROM inventory", conn)
Dim dt As New DataTable
DATA1.Fill(dt)
Me.dgvInventory.DataSource = dt
conn.Close()
End Sub
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\invent.accdb;Persist Security Info=False;")
conn = New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\invent.accdb;Persist Security Info=False;"
Me.RefreshData()
If Not conn.State = ConnectionState.Open Then
conn.Open()
End If
Dim sql As String
sql = "INSERT into inventory (pcode, psup, pcat, pdescript, pstock, piprice, ptprice, pdate) values (@icode, @isup, @icat, @idesc, @istock, @iprice, @iptprice, @idate) "
Dim cmd As New OleDb.OleDbCommand(sql, conn)
cmd.Parameters.Add(New OleDb.OleDbParameter("@icode", txtPcode.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@isup", txtPsup.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@icat", txtPcat.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@idesc", txtPdesc.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@istock", txtPstock.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@iprice", txtPprice.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@iptprice", txtPtprice.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@idate", txtPdate.Text))
cmd.ExecuteNonQuery()
conn.Close()
RefreshData()
MsgBox("Data Successfully Added!", MsgBoxStyle.Information, "Success")
Johnny Joe 0 Newbie Poster
Santanu.Das 125 Santanu Das
Johnny Joe 0 Newbie Poster
Santanu.Das 125 Santanu Das
Johnny Joe 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Miurei 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.