Jul 15th, 2010, 01:39 AM
#1
Thread Starter
Lively Member
[RESOLVED] Need of DatagridView Codes???
Hi All,
I have queries in "Datagridview"(Vb.net)
Consider, Now i have Datetimepicker1,DatetimePicker2,Datatgridview Tools.
Then I have table with fieldnames " Username", "Starttime" and Date"
Problem:
I want to display all three field's Records in DatagridView as per Selected dates between Datetimepicker1 and DatetimePicker2. This should be based "Date" field in Table.
Can any one of Post Your Own Codes for This?
It will be More useful to me.
Jul 15th, 2010, 05:05 AM
#2
Re: Need of DatagridView Codes???
Do you know how to load the records into the datagridview?
Use the SQLCommand "Select... From... Where..." to load the records you need.
Jul 15th, 2010, 06:13 AM
#3
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
Hi Radjesh Klauke,
Thanks for Lookup my forum.
I have i idea about Sql command.
- Select username,startime,date from username where date between '"&datetimepicker1.value&"' and '"&datetimepicker2.value&"'.
I know this Query.
But i need to know how to populate that selected field records to Datagridview?
Jul 15th, 2010, 07:24 AM
#4
Re: Need of DatagridView Codes???
??? Which selected fields? Now you're talking about something else.
Start from the beginning and tell us what you already have and what you are trying to achieve.
Perhaps a screenshot...
Jul 15th, 2010, 07:45 AM
#5
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
Dim dat1, dat2 As Date
dat1 = DateTimePicker1.Value
dat2 = DateTimePicker2.Value
connetionString = "Data Source=V2;Initial Catalog=Hipaa;Trusted_Connection=True"
connection = New SqlConnection(connetionString)
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT [username],[startime],[endtime],[totaltime] FROM [paa].[dbo].[table1] WHERE convert(varchar(11),date,101) between '" & dat1 & "' and '" & dat2 & "'", connection)
Dim ds As DataSet = New DataSet
da.Fill(ds, "table1")
Now, You consider above code, in that, i coded till fill in dataset.
Now, I need to populate that in datagridview..
Post sample code???
Jul 15th, 2010, 08:11 AM
#6
Re: Need of DatagridView Codes???
Aha, you don't know how to fill the Datagrid. I need to do something else fisrt. Will be back.
Jul 15th, 2010, 08:24 AM
#7
Re: Need of DatagridView Codes???
Here's a small example:
vb.net Code:
mysqlAdapter.Fill(mysqlTable)
mysqlReader = mysqlComm.ExecuteReader
While mysqlReader.Read
sbar_progress.Value += 1
yourdagrid.DataSource = mysqlTable
End While
What kind of database are you using btw?
Jul 16th, 2010, 12:23 AM
#8
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
Hi Radjesh Klauke!!
I am using SQL server 2005.
I have one clarification in your code. You have used "sbar_progress".
Can u say, why u used "sbar_progress"?
Jul 16th, 2010, 02:07 AM
#9
Re: Need of DatagridView Codes???
Never mind that. You don't need it.
You only need to add the data like: yourdatagridview.DataSource = ds.DefaultViewManager
Jul 16th, 2010, 03:54 AM
#10
Re: Need of DatagridView Codes???
Jul 16th, 2010, 04:50 AM
#11
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
Hi Radjesh Klauke,
I couldn't get correct solution till now. I had used your last link also, which u said.
In that site,
' Bind the DataGrid control to the Contacts DataTable.
dgContacts.SetDataBinding(m_DataSet, "Contacts")
This code also not working
Jul 16th, 2010, 04:52 AM
#12
Re: Need of DatagridView Codes???
Rewrite your code like the example and it'll work.
Jul 16th, 2010, 05:11 AM
#13
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
' Bind the DataGrid control to the Contacts DataTable.
dgContacts.SetDataBinding(m_DataSet, "Contacts")
In above line can you about 'dgContacts', because im not sure about that.
Is it Datagrid name?
Jul 16th, 2010, 05:29 AM
#14
Re: Need of DatagridView Codes???
dgContacts is the name of the DatagridView.
Jul 16th, 2010, 05:35 AM
#15
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
I attached datagrid screen.
Should we add columns in datagrid task? u can see that in attached screen.
Can u say that details?
Attached Images
Jul 16th, 2010, 05:52 AM
#16
Re: Need of DatagridView Codes???
AAAAH!!! The code works fine. What's the name of your datagrid?
If I could connect to the server send me the password etc via PM.
Jul 16th, 2010, 05:57 AM
#17
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
Im using default name for datagrid "DataGridView1"
Jul 16th, 2010, 06:00 AM
#18
Re: Need of DatagridView Codes???
If the name is DatagridView1, then why did you use "dgContacts"?
Or try: DataGridView1.DataSource= ds.Tables(0)
Jul 16th, 2010, 06:21 AM
#19
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
now i facing following problem. refer screenshot.
Attached Images
Jul 16th, 2010, 07:51 AM
#20
Re: Need of DatagridView Codes???
What are you doing? I gave it only as example and it seems you also don't know how to connect to the database. You need to begin from the start. Do you know how to connect to the database?
Here's how you can do everything: http://www.vbnettutorial.net/?Id=125...t-DataGridView
Jul 17th, 2010, 01:27 AM
#21
Thread Starter
Lively Member
Re: Need of DatagridView Codes???
Hmmm.. Very nice link you posted Mr.Radjesh Klauke..
http://www.vbnettutorial.net/?Id=125...t-DataGridView
It was very useful.
Now, i can populate date in Datagridview.
Thank you for Instant help from you. I never forgot your help and your name.
Thank you so much...
Jul 17th, 2010, 05:00 AM
#22
Re: Need of DatagridView Codes???
Ola,
Nice to hear that it finally worked. Don't forget to set the question as "Resolved" and rate peoples post if it was very helpfull
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width