943,547 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 5257
  • VB.NET RSS
Jul 21st, 2009
0

Fill DataGrid with SqlServer Table

Expand Post »
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. "
VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dizzzy is offline Offline
23 posts
since Jul 2009
Jul 21st, 2009
0

Re: Fill DataGrid with SqlServer Table

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.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
431 posts
since May 2009
Jul 21st, 2009
0

Re: Fill DataGrid with SqlServer Table

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>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dizzzy is offline Offline
23 posts
since Jul 2009
Jul 21st, 2009
0

Re: Fill DataGrid with SqlServer Table

Fixed i set autogenerate to false and create columns myself Thank You
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dizzzy is offline Offline
23 posts
since Jul 2009
Jul 21st, 2009
0

Re: Fill DataGrid with SqlServer Table

Ok, good to know.
take care.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
431 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Combo Box not populating
Next Thread in VB.NET Forum Timeline: loop help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC