Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

VS 2005 txtStName Exception error.

$
0
0
Hi the first block of code upto line four is my connection portion.

Code:

  Dim strConn As String = "Data Source = (local); initial catalog = School; User ID = sa; password = 123;"
    Dim cnSql As New SqlConnection(strConn)
    Dim daSql As New SqlDataAdapter
    Dim dsSql As New DataSet



this is insert button portion.
    Private Sub btnStInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStInfo.Click


        '      Try
              Dim strIns As String = "insert into StInfo (St_Name, St_Address, St_Age, St_Image) values ( '" & txtStName & "','" & txtStAdd & "', '" & txtStAge & "', '" & PictureBox1 & "')"

        Dim cmdSql As New SqlCommand(strIns, cnSql)
        cmdSql.CommandType = CommandType.Text
        daSql.InsertCommand = cmdSql
        daSql.InsertCommand.ExecuteNonQuery()

        MsgBox("Record Inserted")
        Clear()
        '        Catch ex As Exception
        MsgBox("Record failed to be inserted")

        '      End Try




    End Sub


I receive this exception error.

The name "txtStName" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>