2017-04-17 1 views
-1

enter image description hereキーワードエラー

public string ss = "Data Source=D\\SQLEXPRESS;Initial Catalog=gym;Integrated Security=True"; 

    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) 
    { 

     string q2 = "insert into database.gym (name,weight,height,add_class,gender,fees) values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.comboBox1.Text + "','" + this.comboBox2.Text + "','" + this.comboBox3.Text + " ') ;"; 
     SqlConnection con = new SqlConnection(ss); 
     SqlCommand cmd = new SqlCommand(q2, con); 
     SqlDataReader read; 
     try 
     { 
      con.Open(); 
      read = cmd.ExecuteReader(); 
      MessageBox.Show("Welcome to our gym"); 
      while (read.Read()) { }; 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
+0

のですか? – Ariwibawa

+1

'Database'は' Sql Server'の* reserved *キーワードです。あなたは本当に 'Database'という名前のスキーマを持っていますか? –

+0

接続文字列から、データベース名はgymです。正しい構文は、挿入クエリの** databasename.schema.tablename **です。あなたのコマンドは 'INSERT INTO gym.schema.table'である必要があります – Raj

答えて

0
insert into database.gym 

代わりにこの使用の有効なテーブル名

insert into Table 

正しい構文は、これらのクエリ内のデータベースが何であるかを[Database].[Schema].[TableName]

+0

エラーが表示されます(「無効なオブジェクト名gym.schema.customer」)。どうすればよいですか? @saurabh –

+0

あなたは単語スキーマを使用するはずがありません、gym.dbo.customerを試してみてください。スキーマをdbo – Saurabh

+0

に置き換えても、gym.dbo.customerを試しましたが、別のエラーが「無効なオブジェクト名gym.dbo.customer」と表示されます –