数据命令插入问题 [英] INSERT problem with DATA COMMAND

查看:58
本文介绍了数据命令插入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个好友

Hi Every Buddy

Public con_str As String = "provider=microsoft.jet.oledb.4.0;data source=|datadirectory|\damyar.mdb;"
Dim con As New OleDbConnection
Dim com As New OleDbCommand

        con.ConnectionString = con_str
       
        com.CommandType = CommandType.Text
        com.CommandText = "INSERT into Talgih VALUES(@ID_talgih,@ID_key,@talgih_type,@talgih_date_y,@talgih_date_m,@talgih_date_d,@talgih_nobat,@ID_sperm,@sh_gav_nar,@gav_laktasion,@mamoor)"

        com.Parameters.AddWithValue("ID_talgih", txt_ID_talgih.Text)
        com.Parameters.AddWithValue("ID_key", txt_ID_key)
        com.Parameters.AddWithValue("talgih_type", s)
        com.Parameters.AddWithValue("talgih_date_y", txt_talgih_date_y)
        com.Parameters.AddWithValue("talgih_date_m", txt_talgih_date_m)
        com.Parameters.AddWithValue("talgih_date_d", txt_talgih_date_d)
        com.Parameters.AddWithValue("talgih_nobat", txt_talgih_nobat)
        com.Parameters.AddWithValue("ID_sperm", txt_ID_sperm)
        com.Parameters.AddWithValue("sh_gav_nar", txt_sh_gav_nar)
        com.Parameters.AddWithValue("gav_laktasion", txt_gav_laktasion)
        com.Parameters.AddWithValue("mamoor", txt_mamoor)

        con.Open()
        com.ExecuteNonQuery()
        con.Close()



当我运行该程序时,我看到错误(ExecuteNonQuery:连接属性尚未初始化.)



When i Run This Program , i see Error (ExecuteNonQuery: Connection property has not been initialized.)

推荐答案

您没有任何链接com和con的链接. .打开连接(con),但未设置com的连接属性.

BTW,com和con非常相似-也许考虑使用更有意义(但不太相似)的变量名...
You don''t have anything linking com and con... You open your connection (con), but you don''t set the connection property of com.

BTW, com and con are very similar - perhaps consider more meaningful (and less similar) variable names...


我认为您已经忘记设置OleDbCommand 的连接了,所以在呼叫ExecuteNonQuery之前的某处添加此行:

I think you have forgotten to set the connection of your OleDbCommand , so add this line somewhere before the call to ExecuteNonQuery :

com.Connection = con



希望对您有帮助



Hope It Helps


您忘了先将com连接到con连接

com.Connection = con
You Forgot to connect first the com to your con connection

com.Connection=con


这篇关于数据命令插入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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