无法在表中插入行。使用* .sdf文件 [英] Not able to insert row in table. using *.sdf file

查看:95
本文介绍了无法在表中插入行。使用* .sdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我处理以下代码

please help me with the following code

Dim conn As SqlCeConnection = Nothing

     
      Try
          conn = New SqlCeConnection("Data Source = MyDb.sdf; Password =''")
          conn.Open()



          Dim cmd As SqlCeCommand = conn.CreateCommand()
          
          ''cmd.CommandText = "INSERT INTO Customer_Details ([Cust_Order], [Customer_Name]) Values('1', '" + txtCustomer.Text + "')"
          cmd.CommandText = "INSERT INTO Customer_Details (Cust_Order, Customer_Name) Values(1, '" + txtCustomer.Text + "')"
          cmd.ExecuteNonQuery()
         
          cmd.CommandText = "SELECT * FROM Customer_Details"
         
      Catch
          MessageBox.Show("Database not connected")
      End Try







我能够连接数据库但无法使用值填充表..让我知道我哪里出错了。谢谢你提前




I'm able to connect with database but not able to populate table with values.. Let me know where I am going wrong.Thank you in advance

推荐答案

究竟为什么那不起作用将取决于你,最让你失望的是部分。

重要的是不要使用匿名捕获 - 你丢弃了所需的信息解决这个问题。

而不是写:

Exactly why that doesn't work is going to be down to you, for the most part.
The important thing is not to use anonymous catches - you are throwing away information you need in order to solve this.
Instead of writing:
Catch
    MessageBox.Show("Database not connected")
End Try

试试这个:

Try this:

Catch ex As Exception
    MessageBox.Show(String.Format("Unable to insert values:\n{0}", ex.ToString()))
End Try

这至少可以让你对出现的问题有所了解。



我的猜测?您的表没有这些列,或者它的值为1,或者它是一个标识字段。

Which will at least give you an overview of what is going wrong.

My guess? Either your table doesn't have those columns, or it has a value of 1, or it's an Identity field.


这篇关于无法在表中插入行。使用* .sdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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