I have following codes

str2 = "select sno,name from employees where sno =" & Val(Me.TextBox1.Text)
            cmd2 = New SqlClient.SqlCommand(str2, con)
            da2 = New SqlClient.SqlDataAdapter(cmd2)
            dt2 = New DataTable
            da2.Fill(dt2)

Now dt2 has two columns as sno and name
But I want to add a 3rd column city type char(80)

Please help

>But I want to add a 3rd column city type char(80).
DataTable.Columns.Add method.

dt2.Columns.Add("City")
 da2.Fill(dt2)

>But I want to add a 3rd column city type char(80).
DataTable.Columns.Add method.

dt2.Columns.Add("City")
 da2.Fill(dt2)

ok that works but in following codes

str = "SELECT RANK() OVER(ORDER BY acccode) AS sno,count(acccode) as sno,acccode,COUNT(Date) AS vou_no, SUM(Qty) AS Qty, SUM(Qty*weight) AS weight  FROM gpass where Date between '" & Me.dtp_first.Text & "' and  '" & Me.dtp_last.Text & "' GROUP BY acccode"
            dt = GetTable(str)
            dt.Columns.Add("tittle")

            Dim cmd As New SqlClient.SqlCommand("UPDATE dt SET tittle=(SELECT top 1 desc1 FROM master WHERE master.code=dt.acccode)", con)
            cmd.ExecuteNonQuery()

the error message appears
invalid object name 'dt'.

How to add datatable reference in Update statement?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.