2014-09-25 90 views
0

請幫忙指教我剛開始寫附加信息:無效的對象名稱信息「vb.net

我使用SQL Server Management Studio中2012 表名是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 

的錯誤是

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

Additional information: Invalid object name 'info'. 

回答

0

在您的連接字符串缺少部分
數據庫= yourDa tabaseName;

Initial Catalog = yourDatabaseName;

沒有這個鍵查詢執行對那裏沒有INFO

+0

非常感謝主席先生的主數據庫,我嘗試 – Pornjarean 2014-09-25 16:19:17

+0

YES!這行得通 !!並非常感謝你^^ – Pornjarean 2014-09-25 16:22:56

+0

很高興能有所幫助。我發現你是這個網站的新用戶,所以我建議閱讀[如何接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-工作) – Steve 2014-09-25 16:25:11