使用c#.net从visual studio 2010将数据插入到ms access database 2007中 [英] Inserting data into ms access database 2007 from visual studio 2010 using c#.net

查看:53
本文介绍了使用c#.net从visual studio 2010将数据插入到ms access database 2007中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是.net的新手,我正在尝试使用visual c#从visual studio 2010向ms access database 2007插入一条记录。 />
我得到一个例外说明:

Oledb异常未处理

对象VisitingCard_Insert不是存储过程。



我google了很多,但还没有找到解决方案。请有人建议我做什么吗?



visual studio 2010
ms access database 2007









代码:

Hi ,

I am new to .net and i am trying to insert a record into ms access database 2007 from visual studio 2010 using visual c#.
I got an exception stating:
"Oledb exception unhandled"
Object VisitingCard_Insert is not a stored procedure.

I googled a lot and am yet to find the solution .Please can anyone suggest me what to do?

visual studio 2010
ms access database 2007




Code:

public partial class Form1 : Form
   {
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\SR050\\Documents\\VisitingCard.accdb");
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            OleDbCommand cmd = new OleDbCommand("VisitingCard_Insert", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Names", textBox1.Text);
            cmd.Parameters.AddWithValue("@Organization", textBox2.Text);
            cmd.Parameters.AddWithValue("@Location", textBox3.Text);
            cmd.Parameters.AddWithValue("@PhoneNo", textBox4.Text);
            cmd.Parameters.AddWithValue("@EmailId", textBox5.Text);
            int result = cmd.ExecuteNonQuery();
            con.Close();
            if (result > 0)
             {
                MessageBox.Show("Inserted Successfully");
             }
          
         }
   }

推荐答案

VisitingCard_Insert 存储过程存在于您的访问数据库中吗?
Did VisitingCard_Insert stored procedure exist in your access database??


这篇关于使用c#.net从visual studio 2010将数据插入到ms access database 2007中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆