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