VS 2008 [RESOLVED] Need of DatagridView Codes???-VBForums
Results 1 to 22 of 22

Thread: [RESOLVED] Need of DatagridView Codes???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Resolved [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.

  2. #2
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    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?

  4. #4
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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...


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    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???

  6. #6
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  7. #7
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Need of DatagridView Codes???

    Here's a small example:

    vb.net Code:
    1. mysqlAdapter.Fill(mysqlTable)
    2. mysqlReader = mysqlComm.ExecuteReader
    3.  
    4. While mysqlReader.Read
    5.     sbar_progress.Value += 1
    6.     yourdagrid.DataSource = mysqlTable
    7. End While

    What kind of database are you using btw?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    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"?

  9. #9
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  10. #10
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Need of DatagridView Codes???



    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    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

  12. #12
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Need of DatagridView Codes???

    Rewrite your code like the example and it'll work.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    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?

  14. #14
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Need of DatagridView Codes???

    dgContacts is the name of the DatagridView.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    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 Attached Images  

  16. #16
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: Need of DatagridView Codes???

    Im using default name for datagrid "DataGridView1"

  18. #18
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Need of DatagridView Codes???

    If the name is DatagridView1, then why did you use "dgContacts"?

    Or try: DataGridView1.DataSource= ds.Tables(0)


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: Need of DatagridView Codes???

    now i facing following problem. refer screenshot.
    Attached Images Attached Images  

  20. #20
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Resolved 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...

  22. #22
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.