Click here to Skip to main content
15,905,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: Changing the datatype of strings Pin
KeesVer4-Dec-06 1:11
KeesVer4-Dec-06 1:11 
QuestionMenu Events Pin
Mark F.3-Dec-06 9:48
Mark F.3-Dec-06 9:48 
AnswerRe: Menu Events Pin
mav.northwind3-Dec-06 10:09
mav.northwind3-Dec-06 10:09 
Questionsearch in access database Pin
suma123823-Dec-06 7:27
suma123823-Dec-06 7:27 
QuestionSynchronized in C# Pin
gaotter3-Dec-06 6:30
gaotter3-Dec-06 6:30 
AnswerRe: Synchronized in C# Pin
Nader Elshehabi3-Dec-06 8:20
Nader Elshehabi3-Dec-06 8:20 
AnswerRe: Synchronized in C# Pin
Judah Gabriel Himango3-Dec-06 12:24
sponsorJudah Gabriel Himango3-Dec-06 12:24 
QuestionSyntax error in INSERT INTO statement. Pin
VirtualG3-Dec-06 5:54
VirtualG3-Dec-06 5:54 
Hi all,

I'm very new to programming in C# (and programming in general). I'm getting "Syntax error in INSERT INTO statement." and I haven't got a clue why.

Here's the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace dbTest
{
    public partial class Form1 : Form
    {
        String conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\MasterInventory2.mdb";
        OleDbConnection con = new OleDbConnection();
        DataTable dtCardlist = new DataTable();
        DataTable dtTemp = new DataTable();
        OleDbDataAdapter daCardlist;

        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            //Get the data from MasterInventory into my datagridview.
            con.ConnectionString = conString;
            daCardlist = new OleDbDataAdapter("Select * From Cardlist", con);
            daCardlist.Fill(dtCardlist);
            dataGridView1.DataSource = dtCardlist;           
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //1. the InsertCommand
            con.Open();
            daCardlist.InsertCommand = con.CreateCommand();
            daCardlist.InsertCommand.CommandText = "INSERT INTO Cardlist "+
                "(Name, Set, Cost, Type, PowTgh, Rules, Rarity) "+
                "VALUES "+
                "(?,?,?,?,?,?,?)";
            daCardlist.InsertCommand.Connection = con;
            daCardlist.InsertCommand.Parameters.Add("Name", OleDbType.Char, 0, "Name");
            daCardlist.InsertCommand.Parameters.Add("Set", OleDbType.Char, 0, "Set");
            daCardlist.InsertCommand.Parameters.Add("Cost", OleDbType.Char, 0, "Cost");
            daCardlist.InsertCommand.Parameters.Add("Type", OleDbType.Char, 0, "Type");
            daCardlist.InsertCommand.Parameters.Add("PowTgh", OleDbType.Char, 0, "PowTgh");
            daCardlist.InsertCommand.Parameters.Add("Rules", OleDbType.Char, 0, "Rules");
            daCardlist.InsertCommand.Parameters.Add("Rarity", OleDbType.Char, 0, "Rarity");

            //1.1 Test the Insert command
            DataRow newRow = dtCardlist.NewRow();
            newRow["Name"] = "testCard2";
            newRow["Set"] = "TST";
            newRow["Cost"] = "Cost";
            newRow["Type"] = "Type";
            newRow["PowTgh"] = "PowTgh";
            newRow["Rules"] = "Rules";
            newRow["Rarity"] = "Rarity";

            dtCardlist.Rows.Add(newRow);
            daCardlist.Update(dtCardlist);
            con.Close();
            
            /*
            //WORKING VERSION USING MASTERINVENTORY.MDB  
            con.Open();
            daCardlist.InsertCommand = con.CreateCommand();
            daCardlist.InsertCommand.CommandText = "INSERT INTO Cardlist (Name, Cost, Type) VALUES (?,?,?)";
            daCardlist.InsertCommand.Connection = con;
            daCardlist.InsertCommand.Parameters.Add("Name", OleDbType.Char, 0, "Name");
            daCardlist.InsertCommand.Parameters.Add("Cost", OleDbType.Char, 0, "Cost");
            daCardlist.InsertCommand.Parameters.Add("Type", OleDbType.Char, 0, "Type");
            
            //1.1 Test the Insert command
            DataRow newRow = dtCardlist.NewRow();
            newRow["Name"] = "testCard3";
            newRow["Cost"] = "Cost";
            newRow["Type"] = "Type";

            dtCardlist.Rows.Add(newRow);
            daCardlist.Update(dtCardlist);
            con.Close();
            */

       }

    }
}


I suspect that it's something really simple, but I just don't see it. Sigh | :sigh:
Any help is appreciated.
AnswerRe: Syntax error in INSERT INTO statement. Pin
Guffa3-Dec-06 7:28
Guffa3-Dec-06 7:28 
GeneralRe: Syntax error in INSERT INTO statement. Pin
VirtualG3-Dec-06 8:55
VirtualG3-Dec-06 8:55 
QuestionFiltering the Gridview Pin
fahiemulleh3-Dec-06 4:31
fahiemulleh3-Dec-06 4:31 
QuestionDOM class Pin
h@s@n3-Dec-06 3:38
h@s@n3-Dec-06 3:38 
AnswerRe: DOM class Pin
George L. Jackson3-Dec-06 4:40
George L. Jackson3-Dec-06 4:40 
Questionpublic variable Pin
microuser_20003-Dec-06 3:34
microuser_20003-Dec-06 3:34 
AnswerRe: public variable Pin
George L. Jackson3-Dec-06 4:17
George L. Jackson3-Dec-06 4:17 
AnswerRe: public variable Pin
CPallini3-Dec-06 6:50
mveCPallini3-Dec-06 6:50 
Questioncode to make enable button in c#.net Pin
ursbuddy3-Dec-06 0:47
ursbuddy3-Dec-06 0:47 
AnswerRe: code to make enable button in c#.net Pin
Christian Graus3-Dec-06 0:51
protectorChristian Graus3-Dec-06 0:51 
AnswerRe: code to make enable button in c#.net Pin
kourvoisier3-Dec-06 12:30
kourvoisier3-Dec-06 12:30 
Questionproblem for Security in Sql 2005 Express. Pin
hdv2122-Dec-06 23:21
hdv2122-Dec-06 23:21 
AnswerRe: problem for Security in Sql 2005 Express. Pin
minnie mouse3-Dec-06 11:53
minnie mouse3-Dec-06 11:53 
QuestionHow to create the console of editing of the register on C#? Pin
Andrey Azarov2-Dec-06 23:16
Andrey Azarov2-Dec-06 23:16 
AnswerRe: How to create the console of editing of the register on C#? Pin
Christian Graus2-Dec-06 23:28
protectorChristian Graus2-Dec-06 23:28 
GeneralRe: How to create the console of editing of the register on C#? Pin
Andrey Azarov3-Dec-06 1:15
Andrey Azarov3-Dec-06 1:15 
AnswerRe: How to create the console of editing of the register on C#? Pin
mav.northwind3-Dec-06 5:08
mav.northwind3-Dec-06 5:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.