VB.net database problem

Questions about programming languages and debugging
Post Reply
User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

VB.net database problem

Post by l0ngb1t »

hey,
i'm trying to write a small thing with vb.net using visual studio 2008
and i am new to VB and the .net framework
however after some google'ng i managed to understand few stuff and i wrote a small example where i have a button, text box and a DataGridView
the user enter a word in the text box and click the button
the program search the database basing on the user word

however it is not working, can anyone help me.
this is the code

Code: Select all

Imports System.Data.OleDb

Public Class Form1
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim query As String
    Dim kword As String

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellContentClick
        kword = txtSearch.Text
        cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\db.accdb;User Id=admin;Password=;")
        query = "SELECT * FROM Table1 where customerID LIKE " + kword + "%"
        cn.Open()
        MsgBox("DB cnx opened")
        cmd = New OleDbCommand(query, cn)
        dr = cmd.ExecuteReader
        dgv.DataSource = dr
        dr.Close()
        cn.Close()
    End Sub
End Class
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

Re: VB.net database problem

Post by l0ngb1t »

ok after more reading i find out that my code above is a mess so i re-write it
but still have a small problem with this line "da.fill(ds)"
the error is: No value given for one or more required parameters.
this is the whole code

Code: Select all

Imports System.Data.OleDb

Public Class Form1
    Dim query As String
    Dim kword As String

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim dbConn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\db.accdb;User Id=admin;Password=;")
        dbConn.Open()
        Dim ds As New DataSet
        kword = txtSearch.Text.ToString
        query = "SELECT * from Table1 where addres LIKE " + kword
        Dim da As New OleDbDataAdapter(query, dbConn)
        da.Fill(ds)
        dgv.DataSource = ds.Tables(0)
        da.Dispose()
        dbConn.Close()


    End Sub
End Class
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Re: VB.net database problem

Post by pseudo_opcode »

Is there still a question there? :?:

Post Reply