HI all .....

I am beginner of VB. net. I m developing a vb.net application program to store, update and search contact information and address. I have completed the data. I have used ms access as my backend. I enter data like wise;

Dim con As New ADODB.Connection

        Dim tmp As New ADODB.Recordset
        Dim s As String

        con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"
        con.Open()
        s = "select * from add1"
        tmp.Open(s, con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
.
.
.
tmp.AddNew()
        tmp.Fields("ID").Value = T18.Text
MsgBox("Record Saved")
        Exit Sub

And to search these type of data i have used separate forms by providing the links of forms in an one search form.

I have given parameters like name, country, org, email to search the contact. I need to show them in a data grid in the form. suppose i insert name in the text box and press button search then the resembling names and their information should be displayed in the data grid. I would be very grateful if anyone helps me to solve this problem.

Waiting for the replys.

Sincerly
Kshiteesh

Hi,

Check this Code:
Add a Datgrid to ur Form.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dim sSQL As String
Dim DA As OleDbDataAdapter
Dim DS As DataSet
Dim ConnStr As String ="Your Connection String"
sSQL = "SELECT * FROM MyTable"
DA = New OleDbDataAdapter(sSQL, ConnStr)
DS = New DataSetDA.Fill(DS, "TabName")
DatGrid1.DataSource = DS.Tables("TabName")
End Sub

:)

REgards
Veena

"to save data in the sql server write this code"


Private Sub button_save(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.save
dim cmd = new sqlcommand("insert into table_name values('"& txtname.txt & "')",con)
dim ds as dataset
dim da as sqldataadaptor(cmd)
com.executenonquery
msgbox"saved"

"and for diaplay in datagrid please write this code on the form load event"

dim cmd = new sqlcommand("select * from table_name",con)
dim ds as dataset
dim da as sqldataadaptor(cmd)
da.fill(ds,"table_ name")
datagrid1.datasource = "TabName"
datagrid1.datamember= ds

just use the sql -query (in submit button click)i.e
dim str as string="select * from tablename where Name ="' & name_txt.text & "'
so the above query -should work when u enter a particular name in textbox called(name_txt)&.
Then all the records related to that name -should b displayed on datagrid or textbox on the form,,,,
regards,
preetham...

Thank you for the reply ......

I did as you said QVeen 72 but it asks oledbdataadapter to be defined and it doesnot recognises new dataset ds it posts an error when you post

DS = New DataSetDA.Fill(DS, "TabName")

It also asks datagrid1 to be declared....I m a bit vague on it. I declared datagrid1 as datagrid in the load event and

Dim DA As OleDb.OleDbDataAdapter

but the problem still persists...

Please help me wot to do????

Hi frens.

Thank you for the help

You gave the code for saving and displaying data in datagrid in SQL.

However, I have MS Access in backend so I faced certain difficulties in it. I also followed Queen V's instructions but it didn't solve my problem. Please Help so that I can do it well.

Private Sub name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New ADODB.Connection
        Dim tmp As New ADODB.Recordset
        Dim s As String
        Dim DA As New OleDb.OleDbDataAdapter
        Dim oledbdataadapter1 As OleDb.OleDbDataAdapter
        Dim db1dataset1 As New DataSet
        Dim DS As DataSet
        Dim datagrid1 As New DataGrid
        con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"
        con.Open()
        s = "SELECT * FROM MyTable where fname='" & TextBox1.Text & "'"
        DA = New OleDb.OleDbDataAdapter(s, con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        DS = New db1DataSet1.add1Row(DS, "add1")
        DatGrid1.DataSource = DS.Tables("add1")
    End Sub

Please help wot is the problem with my code.

Anticipating ur replies.

Kshiteesh

your code seems to be missing the Fill command for the datagrid

DataGrid1.Fill(ds,"add1")

Let us know which part of the code is the error thrown up.

Dear frens,

I m still facing the same problem, I m using VB.net 2007. when i use

Private Sub name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s As String
        Dim tmp As ADODB.Recordset
        Dim ds As New DataSet
        Dim datagrid1 As New DataGrid
        Dim dataview As New DataView
        Dim da As New OleDb.OleDbDataAdapter
        Dim ds1 As New DataSet
        con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"
        con.Open()
        s = "select * from add1 where fname='" & TextBox1.Text & "'"
        tmp.Open(s, con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        Dim ConnStr As String = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"""
        da = New OleDb.OleDbDataAdapter(s, ConnStr)
        ds = New DataSet da.fill(ds, add1")
        datagrid1.DataSource = ds.Tables("add1")
        datagrid1.fill(da, "add1")
    End Sub

In the aforementioned code I get problem when I write

ds = New DataSet da.fill(ds, add1")

it shows build error showing
end of statement expected

and

datagrid1.fill(da, "add1")

shows build error showing
'fill' is not a member of 'System.Windows.Forms.DataGrid'.

I don get any point please help me...and please explain how to overcome this problem. I don't have much time coz most of my time has been lost in this problem.

please help

Hi,

Sorry that was C code not vb
And Recordset Object does exist in VB.net..

check this :

Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=K:\Database\db1.mdb"
Dim conn As OleDbConnection = New OleDbConnection(conStr)
Dim Ssql As String 
ssql = "select * from add1 where fname='" & TextBox1.Text & "'"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(Ssql, conn)  
Dim ds As New DataSet 
da.Fill(ds, "Table1")   
DataGrid1.DataSource = ds.DefaultViewManager

Regards
Veena

Dear frens and especially the ones who have helped me. Hi to all...

The code in form to show data in the data grid is as follows.

But when i tryto run it then it runs and when i click then it shows the InvalidOperationException was unhandled showing error msg.

{"The SelectCommand property has not been initialized before calling 'Fill'."}

how can i overcome this problem

Public Class name

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       [inlinecode] Dim oledbdataadapter1 As New OleDb.OleDbDataAdapter
        Db1DataSet1.Clear()
        oledbdataadapter1.Fill(Db1DataSet1)
    End Sub
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub


    Private Sub name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Db1DataSet1.add1' table. You can move, or remove it, as needed.
        [inlinecode]Me.Add1TableAdapter.Fill(Me.Db1DataSet1.add1)
        Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=K:\Database\db1.mdb"
        Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection(conStr)
        Dim S As String
        Dim datagrid1 As New DataGrid
        S = "select * from add1 where fname='" & TextBox1.Text & "'"
        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(S, con)
        da.Fill(Db1DataSet1, "add1")
        datagrid1.DataSource = Db1DataSet1.DefaultViewManager
    End Sub

    Private Sub Db1DataSet1_Initialized(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)

    End Sub

    Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub Add1BindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add1BindingSource.CurrentChanged

    End Sub

    Private Sub FNameDataGridViewTextBoxColumn_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles FNameDataGridViewTextBoxColumn.Disposed

    End Sub
End Class

please please...anyone who sees this thread...able to help me ...reply........whether it be VEENA, Preetam, Arjun, Kap or any other else.......

I would truely appereciate your great help..

Anticipating the replies...

Regards
Kshiteesh

Thank you Veena ......

I found wot the mistake was......I put the load event code in click event.....

At last my problem is solved.....

Thanks again...

Kshiteesh

Atlast you solved it. I was just changing the code when you posted you comment!. Mark it as solved now!

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.