Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why when i insert data into sql server ce database record not saved
i try this code
VB
Dim ds As New AppDatabase1DataSet
        Dim da As New SqlCeDataAdapter(cmd.CommandText, cn)
        da.Fill(ds, "h_DB")
        If Me.BindingContext(ds, "h_DB").Count = 0 Then
            MessageBox.Show("not empty قاعدة البيانات")
        End If

        If 1 Then
            Try


                cmd.CommandText = "insert into sign_normal_DB (word_A,picture,type,type_name) values ('" & TextBox1.Text & " ' ,? , ' " & TextBox3.Text & " ', ' " & TextBox2.Text & " ' )"
                Dim param As SqlCeParameter = cmd.Parameters.Add("picture", SqlDbType.Image)
                param.Value = imageData
                cmd.ExecuteNonQuery()
                MessageBox.Show("تمت الإضافة بنجاح")
            Catch sqex As SqlCeException
                MessageBox.Show(sqex.ToString(), "فشلت العملية على قاعدة البيانات")
            End Try
            fs.Close()

            'cmd.CommandText = "commit"
            ' cmd.ExecuteNonQuery()
            cn.Close()
            'clear window
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            PictureBox1.Image = Nothing

        Else

            MessageBox.Show("الكلمة موجودة بإمكانك تعديلها من قسم تعديل قاعدة البيانات ")
        End If
Posted
Updated 16-Apr-11 15:44pm
v2
Comments
Fabio V Silva 16-Apr-11 17:27pm    
Do you get any error at all?
Albin Abel 18-Apr-11 6:58am    
Hi debug and see is the flow travels in the right path. By the way what you are having in imageData.

The question mark at your query can be @picture. Then

VB
Dim param As SqlCeParameter = new SqlCeParameter("@picture", SqlDbType.Image)
param.Value = imageData
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery()


Remove your try catch and get get error on hand, let us know your error if not solved.
 
Share this answer
 
Comments
Prerak Patel 18-Apr-11 4:48am    
OP:i try this but i dont have any exception
and still dont save data
hi i still waiting your answer
any body can help me pleas....??
 
Share this answer
 
your insert query is wrong your not passing the parameters correctly. Have a look at this link, Parameterised queries examples[^]
 
Share this answer
 
i edit my query like this
cmd.CommandText = "insert into sign_normal_DB (word_A,picture,type,type_name) values ('" & TextBox1.Text & " ' ,@ItmPic , ' " & TextBox3.Text & " ', ' " & TextBox2.Text & " ' )"
Dim param As SqlParameter = cmd.Parameters.Add("@ItmPic", SqlDbType.Image)
param.Value = imageData
cmd.ExecuteNonQuery()
'dr = cmd.ExecuteReader
MessageBox.Show("data inserted successfully")
Catch sqex As SqlCeException
MessageBox.Show(sqex.ToString(), "فشلت العملية على قاعدة البيانات")
End Try

i see message data inserted successfully
but when i close emulator and see the table , the table dont include new data (why???)

is there any instruction can i do ? please
 
Share this answer
 
Comments
Simon_Whale 19-Apr-11 12:29pm    
Change your query to

cmd.commandtext = "insert into sign_normal_db (Word_A, Picture, type, type_name) values (?,?,?,?)

With cmd.Parameters
.Add("@p1", DbType.VarChar).Value = textbox1.Text
.Add("@p2", DbType.Image).value = imagedata
.Add("@p3", DbType.VarChar).Value = textbox3.Text
.Add("@p4", DbType.VarChar).Value = textbox2.Text
End With

cmd.executeNonQuery

p.s. you should also name your textboxes to something more meaningful too
hind_F 27-Apr-11 16:23pm    
thanks alot

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