Add a field at run time to a table in ado.net
Imports System.Data.SqlClient
Public Class Form1
Dim cn As New SqlConnection("server=.;database=atten;uid=sa;pwd=sa;")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'save
cn.Open()
Dim query, query1, query2 As String
Dim regnum As Integer
query1 = "select max(reg) from sdetail"
Dim cmd1 As New SqlCommand(query1, cn)
regnum = cmd1.ExecuteScalar
TextBox1.Text = regnum
query = "insert into sdetail (name) values(" + " '" + TextBox2.Text + "')"
Dim cmd As New SqlCommand(query, cn)
Dim dr As Integer
dr = cmd.ExecuteNonQuery
query2 = "alter table sattend add " + TextBox1.Text + " varchar(50);"
Dim cmd2 As New SqlCommand(query2, cn)
cmd2.ExecuteNonQuery()
cn.Close()
End Sub
End Class
Line 1: Incorrect syntax near '1037'.
1037 is value in textbox1.text
Questions by arunsudhakar55
Showing Answers 1 - 1 of 1 Answers
Related Answered Questions
Related Open Questions
Add a field at run time to a table in ado.net
Public Class Form1
Dim cn As New SqlConnection("server=.;database=atten;uid=sa;pwd=sa;")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'save
cn.Open()
Dim query, query1, query2 As String
Dim regnum As Integer
query1 = "select max(reg) from sdetail"
Dim cmd1 As New SqlCommand(query1, cn)
regnum = cmd1.ExecuteScalar
TextBox1.Text = regnum
query = "insert into sdetail (name) values(" + " '" + TextBox2.Text + "')"
Dim cmd As New SqlCommand(query, cn)
Dim dr As Integer
dr = cmd.ExecuteNonQuery
query2 = "alter table sattend add " + TextBox1.Text + " varchar(50);"
Dim cmd2 As New SqlCommand(query2, cn)
cmd2.ExecuteNonQuery()
cn.Close()
End Sub
End Class
Line 1: Incorrect syntax near '1037'.
1037 is value in textbox1.text
Profile Answers by arunsudhakar55 Questions by arunsudhakar55
Questions by arunsudhakar55
Related Answered Questions
Related Open Questions