简体   繁体   中英

Additional information: Invalid object name 'info' vb.net

Please help advise I just started writing

I'm using SQL Server Management Studio 2012 Table name is dbo.info

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1

    Dim SQLCon As New SqlConnection("Data Source=SECURITY;Integrated Security=False;User ID=sa;Password=Rapoo;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False")
    Dim cmd As New SqlCommand

    Private Sub btmSave_Click(sender As Object, e As EventArgs) Handles btmSave.Click
        If txtStaff.Text <> "" And txtName.Text <> "" Then
            SQLCon.Open()
            cmd.CommandText = "insert into info (Club,Staff,Name,Age,Gender,Mobile,Mail,Remark) values ('" & lblClub.Text & "','" & txtStaff.Text & "','" & txtName.Text & "','" & txtAge.Text & "','" & txtGender.Text & "','" & txtMobile.Text & "','" & txtMail.Text & "','" & txtRemark.Text & "')"
            cmd.ExecuteNonQuery()
            SQLCon.Close()

        End If
        Clear()
    End Sub

The error is

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Invalid object name 'info'.

In your connection string is missing the part
Database=yourDatabaseName;
or
Initial Catalog=yourDatabaseName;

Without this key your query executes against the MASTER database where there is no INFO table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM