Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Every Buddy

VB
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()


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

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...
 
Share this answer
 
Comments
synctor 17-Nov-11 0:32am    
Thank you
I think you have forgotten to set the connection of your OleDbCommand , so add this line somewhere before the call to ExecuteNonQuery :

VB
com.Connection = con


Hope It Helps
 
Share this answer
 
Comments
synctor 17-Nov-11 0:32am    
Merci Amir Jan
Amir Mahfoozi 17-Nov-11 0:35am    
Good Luck ;)
You Forgot to connect first the com to your con connection

com.Connection=con
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900