无效的对象名称空间

时间:2019-04-05 19:55:08

标签: vb.net

我在SQLServer中创建了一个表,代码的思想是填补空白并单击Insert,然后将一个新用户添加到数据库和DataGridView中,但出现此错误:

  

无效的对象名称“用户”。

单击Insert按钮后出现此错误:

Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim connection As New SqlConnection("Data Source=LAPTOP-DLGJAU3D;Initial Catalog=master;Integrated Security=True")

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        EmployeeListDataGridView.DataSource = GetEmployeeList()
    End Sub

    Private Function GetEmployeeList() As DataTable
        Dim dtEmployees As New DataTable
        Dim connString As String = ConfigurationManager.ConnectionStrings("dbx").ConnectionString

        Using conn As New SqlConnection(connString)
            Using cmd As New SqlCommand("SELECT * FROM dbo.EMPLOYEES", conn)
                conn.Open()
                Dim reader As SqlDataReader = cmd.ExecuteReader()
                dtEmployees.Load(reader)
            End Using
        End Using
        Return dtEmployees
    End Function

    Private Sub BTN_INSERT_Click(sender As Object, e As EventArgs) Handles BTN_INSERT.Click
        Dim command As New SqlCommand("insert into Users(Fname, Lname, age) values('" & TextBoxFN.Text & "','" & TextBoxLN.Text & "'," & TextBoxAGE.Text & ")", connection)
        connection.open()

        If command.ExecuteNonQuery() = 1 Then
            MessageBox.Show("New User Added")
        Else
            MessageBox.Show("User Not Added")
        End If
        connection.close()
    End Sub
End Class

0 个答案:

没有答案