Fill DataGrid with SqlServer Table

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

Join Date: Jul 2009
Posts: 7
Reputation: Dizzzy is an unknown quantity at this point 
Solved Threads: 0
Dizzzy Dizzzy is offline Offline
Newbie Poster

Fill DataGrid with SqlServer Table

 
0
  #1
Jul 21st, 2009
Ok i have this code to retreive data from a Table "Calendar" and the feild within the table are Id,Day ,Month and Year.
When i press the button to run this code and i get the error message "The parameterized query '(@Day varchar(8000),@Month varchar(8000),@Year varchar(8000))Sel' expects the parameter '@Day', which was not supplied. "
  1. Dim con As New System.Data.SqlClient.SqlConnection
  2. con.ConnectionString = ******
  3.  
  4. Dim cmd As System.Data.SqlClient.SqlCommand
  5.  
  6. Dim myDA As System.Data.SqlClient.SqlDataAdapter
  7.  
  8. Dim myDataSet As System.Data.DataSet
  9.  
  10. 'Binding database table to DataGridView
  11.  
  12. cmd = New System.Data.SqlClient.SqlCommand("Select * FROM Calendar", con)
  13.  
  14. If con.State = System.Data.ConnectionState.Closed Then con.Open()
  15.  
  16. myDA = New System.Data.SqlClient.SqlDataAdapter(cmd)
  17.  
  18. myDataSet = New System.Data.DataSet()
  19.  
  20. myDA.Fill(myDataSet, "Calendar")
  21.  
  22. DataGrid.DataSource = myDataSet.Tables("Calendar").DefaultView
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 186
Reputation: jbisono is an unknown quantity at this point 
Solved Threads: 24
jbisono's Avatar
jbisono jbisono is offline Offline
Junior Poster

Re: Fill DataGrid with SqlServer Table

 
0
  #2
Jul 21st, 2009
at the end put DataGrid.DataBind()

also is your datagrid allow to generate the columns automatically, if not i would like to see the datagrid structure and the exact field you are retrieving from the calendar table

Regards.
If your already resolved your issue, flag it as solved.
José Bisonó
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: Dizzzy is an unknown quantity at this point 
Solved Threads: 0
Dizzzy Dizzzy is offline Offline
Newbie Poster

Re: Fill DataGrid with SqlServer Table

 
0
  #3
Jul 21st, 2009
Ok Databind is displaying the records now which is great no i have 2 sets of columns so 2 day 2 month and 2 year, I have autogenerate column to true and thats it i havent declare any columns either
<aspataGrid ID="DataGrid" runat="server" AutoGenerateColumn="true" SelectedIndex="1" >
</aspataGrid>
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: Dizzzy is an unknown quantity at this point 
Solved Threads: 0
Dizzzy Dizzzy is offline Offline
Newbie Poster

Re: Fill DataGrid with SqlServer Table

 
0
  #4
Jul 21st, 2009
Fixed i set autogenerate to false and create columns myself Thank You
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 186
Reputation: jbisono is an unknown quantity at this point 
Solved Threads: 24
jbisono's Avatar
jbisono jbisono is offline Offline
Junior Poster

Re: Fill DataGrid with SqlServer Table

 
0
  #5
Jul 21st, 2009
Ok, good to know.
take care.
If your already resolved your issue, flag it as solved.
José Bisonó
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