0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vbdotnetlover
0

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

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.