[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.
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.
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?
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...
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???
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.
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?
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"?
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
Re: Need of DatagridView Codes???
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
Re: Need of DatagridView Codes???
Rewrite your code like the example and it'll work. ;)
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?
Re: Need of DatagridView Codes???
dgContacts is the name of the DatagridView.
1 Attachment(s)
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?
Re: Need of DatagridView Codes???
AAAAH!!! :p 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.
Re: Need of DatagridView Codes???
Im using default name for datagrid "DataGridView1"
Re: Need of DatagridView Codes???
If the name is DatagridView1, then why did you use "dgContacts"?
Or try: DataGridView1.DataSource= ds.Tables(0)
1 Attachment(s)
Re: Need of DatagridView Codes???
now i facing following problem. refer screenshot.
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
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...
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 ;)