jvcoach23 Posted March 16, 2005 Posted March 16, 2005 how do you update a column in a row in a datatable. This datatable is going to be populated orginally from a database, but after that all the updates to it won't be going back to the database, they are just goign to be used for display. So if i I have a datatable with the column names of Name, col1, col2 and the first row is looks like this.. Name col1 col2 a2 30 15 b2 10 13.3 c2 100 18 now i click on a button1 to update from a text box the value to teh datatable. I know that I want to update col1 where name = a2. How do I do that. I've looked around.. but I must not be using the right key words or not understanding what I'm seeing. let's say the datatables name is dt. someone willing to lend a hand thanks shannon Oh yeah.. I'm using vb.net in a windows form. thanks Quote JvCoach23 VB.Net newbie MS Sql Vet
cheewacheewa Posted March 26, 2005 Posted March 26, 2005 (edited) Search for a specific value by column then change 'This is how i would do it. 'Adding a new data row at the index where info is found 'Using a defualt form with 1 buttons,1 datagrid and a textbox 'Declarations Dim dt As New DataTable("New") Dim dv As New DataView Dim col1 As New DataColumn("A1") Dim dr As DataRow = dt.NewRow Dim int As Integer Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load DataGrid1.DataSource = CreateDatasource() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dv.Table = dt 'Change A1 dv.Sort = ("A1") int = dv.Find("TextToFind") dt.Rows.RemoveAt(int) dr("A1") = TextBox1.Text dt.Rows.InsertAt(dr, int) End Sub Function CreateDatasource() As DataTable dt.Columns.Add(col1) dr("A1") = "TextToFind" dt.Rows.Add(dr) Return dt End Function Edited March 26, 2005 by cheewacheewa Quote
jvcoach23 Posted March 30, 2005 Author Posted March 30, 2005 great.. thanks.. I'll give this a go Quote JvCoach23 VB.Net newbie MS Sql Vet
cheewacheewa Posted March 30, 2005 Posted March 30, 2005 hope it works for ya,could you recommend a good site for mysql? Quote
jvcoach23 Posted April 1, 2005 Author Posted April 1, 2005 sorry.. I'm a Microsoft Sql guy... haven't done anything with mySql. if you ever move over to Sql server.. give a shout.. Quote JvCoach23 VB.Net newbie MS Sql Vet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.