dcsimg
Results 1 to 6 of 6

Thread: Datagridview / Date inserting QuestionS.

  1. #1

    Thread Starter
    Member Ahmed Shahni's Avatar
    Join Date
    Feb 2011
    Posts
    45

    Lightbulb Datagridview / Date inserting QuestionS.

    Dear Sir,

    I have already made a connection to my DataGridview through SQL command and records is displaying on my Windows Form (VB2010).

    Sir, my requirement is I do not want to display complete records and I want only to see the last records of the Datagridview. Pls correct my codes.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As ystem.EventArgs) Handles Button2.Click

    daDG.Fill(dataset, "EmpList")
    DataGridView1.DataSource = dataset
    DataGridView1.DataMember = "EmpList"

    End Sub
    And also Sir, pls advice me how to INSERT date into a Table my code as follows:

    conn = New SqlConnection(connstring)
    Dim sql As String
    sql = "insert into EmpList (Date,EmpName) values(???,'" & Textbox2.text & "')"


    Thanks.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,877

    Re: Datagridview / Date inserting QuestionS.

    I'm not quite sure why you're using a grid if all you want to see is the last row. Is it because you want to be able to add more rows? Do you want to use the other data at all?

  3. #3

    Thread Starter
    Member Ahmed Shahni's Avatar
    Join Date
    Feb 2011
    Posts
    45

    Re: Datagridview / Date inserting QuestionS.

    Sir when Form Load I could see all data around 50 employees in the Datagridview but also I have a command button to check the last record, so I can check the last empId an all.

    Thanks a lot.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,877

    Re: Datagridview / Date inserting QuestionS.

    Why do you want to get the last ID? If it's to create the next ID then you really should be letting the database take care of that. Please provide a full explanation so that we can provide informed advice.

  5. #5

    Thread Starter
    Member Ahmed Shahni's Avatar
    Join Date
    Feb 2011
    Posts
    45

    Re: Datagridview / Date inserting QuestionS.

    Sir,
    Actually this option required by our Accounting dept. indeed the id no we create manually depending on section accountant hence they need to check last record of the Datagridview.

    Also please advice the way to insert the Date I tried with '" # TextDate.Text # "'........it is not working.

    Thanking your cooperation.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,877

    Re: Datagridview / Date inserting QuestionS.

    I'm yet to see the "full" explanation I asked for. Are you saying that you want to get the last record from the database or from the data you already have? Is this ID you're generating the PK for the table or are you using an auto-generated value for that?

    As for inserting a date into a database, it's no different to inserting any other value. You use parameters for all data, so the data type is irrelevant. Follow Blog link in my signature and check out my ADO.NET Parameters post for more info.

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