.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

ผม Insert ใน data base Access ไม่ได้คับ Options · View
zerozaaa
Posted: Monday, October 06, 2008 3:15:04 AM
Rank: มือพระกาฬ
Groups: Member

Joined: 6/13/2008
Posts: 79

ผมมีตารางชื่อว่า test มี  field 2 field คือ id เป็น Auto , text เป็น text ผมเขียน โค๊ด ดังนี้

            string sqlqup;
            string conStrDB;
 
            conStrDB = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            OleDbConnection Conn = new OleDbConnection(conStrDB);
            Conn.Open();
            sqlqup = "INSERT INTO test VALUES(@test)";
            OleDbCommand odc = new OleDbCommand(sqlqup, Conn);
 
            OleDbParameter para_topic = new OleDbParameter();//1 question_topic
            para_topic.ParameterName = "@test";
            para_topic.OleDbType = OleDbType.VarChar;
            para_topic.Value = "1";
            odc.Parameters.Add(para_topic);
 
            odc.ExecuteNonQuery();
            Conn.Close();
            Console.ReadLine();
 

มันฟ้อง error แบบนี้คับ {"Number of query values and destination fields are not the same."}
เป็นเพราะอะไรคับ ต้องแก้ยังไงคับ

 

paedotnet
Posted: Monday, October 06, 2008 10:17:40 AM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 345
Location: bkk

ให้ใส่ชื่อ field ที่ต้องการ insert ด้วยครับเช่นต้องการ insert พารามิเตอร์ @test ลงใน field ที่ชื่อ question_topic ก้เขียนดังนี้

INSERT INTO test (question_topic) VALUES(@test)



[With great power comes great responsibility]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by