Datagrid view using parameters(Plz help)

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2007
Posts: 23
Reputation: Kshiteesh is an unknown quantity at this point 
Solved Threads: 0
Kshiteesh Kshiteesh is offline Offline
Newbie Poster

Datagrid view using parameters(Plz help)

 
0
  #1
Aug 2nd, 2007
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;
  1. Dim con As New ADODB.Connection
  2.  
  3. Dim tmp As New ADODB.Recordset
  4. Dim s As String
  5.  
  6. con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"
  7. con.Open()
  8. s = "select * from add1"
  9. tmp.Open(s, con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
  10. .
  11. .
  12. .
  13. tmp.AddNew()
  14. tmp.Fields("ID").Value = T18.Text
  15. MsgBox("Record Saved")
  16. 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Datagrid view using parameters(Plz help)

 
0
  #2
Aug 2nd, 2007
Hi,

Check this Code:
Add a Datgrid to ur Form.

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


REgards
Veena
Last edited by QVeen72; Aug 2nd, 2007 at 6:35 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 2
Reputation: kap_sharma is an unknown quantity at this point 
Solved Threads: 0
kap_sharma kap_sharma is offline Offline
Newbie Poster

Re: Datagrid view using parameters(Plz help)

 
0
  #3
Aug 2nd, 2007
"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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 82
Reputation: preetham.saroja is an unknown quantity at this point 
Solved Threads: 1
preetham.saroja's Avatar
preetham.saroja preetham.saroja is offline Offline
Junior Poster in Training

Re: Datagrid view using parameters(Plz help)

 
0
  #4
Aug 2nd, 2007
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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 23
Reputation: Kshiteesh is an unknown quantity at this point 
Solved Threads: 0
Kshiteesh Kshiteesh is offline Offline
Newbie Poster

Re: Datagrid view using parameters(Plz help)

 
0
  #5
Aug 3rd, 2007
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
  1. 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
  1. Dim DA As OleDb.OleDbDataAdapter
but the problem still persists...

Please help me wot to do????
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 23
Reputation: Kshiteesh is an unknown quantity at this point 
Solved Threads: 0
Kshiteesh Kshiteesh is offline Offline
Newbie Poster

Re: Datagrid view using parameters(Plz help)

 
0
  #6
Aug 6th, 2007
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.

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

Please help wot is the problem with my code.

Anticipating ur replies.

Kshiteesh
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: Datagrid view using parameters(Plz help)

 
0
  #7
Aug 6th, 2007
your code seems to be missing the Fill command for the datagrid

  1. DataGrid1.Fill(ds,"add1")

Let us know which part of the code is the error thrown up.
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 23
Reputation: Kshiteesh is an unknown quantity at this point 
Solved Threads: 0
Kshiteesh Kshiteesh is offline Offline
Newbie Poster

Re: Datagrid view using parameters(Plz help)

 
0
  #8
Aug 7th, 2007
Dear frens,

I m still facing the same problem, I m using VB.net 2007. when i use
  1. Private Sub name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim s As String
  3. Dim tmp As ADODB.Recordset
  4. Dim ds As New DataSet
  5. Dim datagrid1 As New DataGrid
  6. Dim dataview As New DataView
  7. Dim da As New OleDb.OleDbDataAdapter
  8. Dim ds1 As New DataSet
  9. con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"
  10. con.Open()
  11. s = "select * from add1 where fname='" & TextBox1.Text & "'"
  12. tmp.Open(s, con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
  13. Dim ConnStr As String = "provider=microsoft.jet.oledb.4.0;data source=K:\Database\db1.mdb"""
  14. da = New OleDb.OleDbDataAdapter(s, ConnStr)
  15. ds = New DataSet da.fill(ds, add1")
  16. datagrid1.DataSource = ds.Tables("add1")
  17. datagrid1.fill(da, "add1")
  18. End Sub
  19.  

In the aforementioned code I get problem when I write
  1. ds = New DataSet da.fill(ds, add1")
  2.  
it shows build error showing
end of statement expected

and

  1. 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Datagrid view using parameters(Plz help)

 
0
  #9
Aug 7th, 2007
Hi,

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

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

Regards
Veena
Last edited by QVeen72; Aug 7th, 2007 at 10:08 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 23
Reputation: Kshiteesh is an unknown quantity at this point 
Solved Threads: 0
Kshiteesh Kshiteesh is offline Offline
Newbie Poster

Re: Datagrid view using parameters(Plz help)

 
0
  #10
Aug 8th, 2007
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.
  1. {"The SelectCommand property has not been initialized before calling 'Fill'."}

how can i overcome this problem
  1. Public Class name
  2.  
  3. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  4.  
  5. End Sub
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. [inlinecode] Dim oledbdataadapter1 As New OleDb.OleDbDataAdapter
  8. Db1DataSet1.Clear()
  9. oledbdataadapter1.Fill(Db1DataSet1)
  10. [/inlinecode]
  11. End Sub
  12. Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
  13.  
  14. End Sub
  15.  
  16.  
  17. Private Sub name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  18. 'TODO: This line of code loads data into the 'Db1DataSet1.add1' table. You can move, or remove it, as needed.
  19. [inlinecode]Me.Add1TableAdapter.Fill(Me.Db1DataSet1.add1)
  20. Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=K:\Database\db1.mdb"
  21. Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection(conStr)
  22. Dim S As String
  23. Dim datagrid1 As New DataGrid
  24. S = "select * from add1 where fname='" & TextBox1.Text & "'"
  25. Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(S, con)
  26. da.Fill(Db1DataSet1, "add1")
  27. datagrid1.DataSource = Db1DataSet1.DefaultViewManager
  28. [/inlinecode]
  29. End Sub
  30.  
  31. Private Sub Db1DataSet1_Initialized(ByVal sender As Object, ByVal e As System.EventArgs)
  32.  
  33. End Sub
  34.  
  35. Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
  36.  
  37. End Sub
  38.  
  39. Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  40.  
  41. End Sub
  42.  
  43. Private Sub Add1BindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add1BindingSource.CurrentChanged
  44.  
  45. End Sub
  46.  
  47. Private Sub FNameDataGridViewTextBoxColumn_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles FNameDataGridViewTextBoxColumn.Disposed
  48.  
  49. End Sub
  50. 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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC