Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have developed a code for insert data to sql compact server?

C#
private void btnOK_Click(object sender, EventArgs e)
        {
            string connetionString = null;

            connetionString = "Data Source=stockDb.sdf;Persist Security Info=False";


            using (SqlCeConnection con = new SqlCeConnection(connetionString))
            {
        
                con.Open();
                SqlConnection.
            

                string sqlquery = ("insert into Enquiry(userName,cusName,cusContact,moreDetails,tktType,noPax,firstStatus,secStatus,thirdStatus)Values(@uName,@cName,@cContact,@mDetails,@tType,@nPax,@fStatus,@sStatus,@tStatus)");

                SqlCeCommand command = new SqlCeCommand(sqlquery, con);



                    int value = Convert.ToInt32(Cus_PaxNo.Text);

                    command.Parameters.AddWithValue("@uName", Loginlbl.Text);
                    command.Parameters.AddWithValue("@cName", Cus_Name.Text);
                    command.Parameters.AddWithValue("@cContact", Cus_Contact.Text);
                    command.Parameters.AddWithValue("@mDetails", Cus_Details.Text);
                    command.Parameters.AddWithValue("@tType", Cus_TicketType.Text);
                    command.Parameters.AddWithValue("@nPax", value);
                    command.Parameters.AddWithValue("@fStatus", Cus_FirstStatus.Text);
                    command.Parameters.AddWithValue("@sStatus", Cus_SecondStatus.Text);
                    command.Parameters.AddWithValue("@tStatus", Cus_ThirdStatus.Text);
                    command.ExecuteNonQuery();

                        MessageBox.Show("Password Accepted");

                }


command.ExecuteNonQuery();
this code gives me an error saying.


An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException'occured in System.Data.SqlserverCe.Dll

What i can do for this to solve the issue.
Posted

1 solution

Start by finding out what the reported problem is:
Add a try...catch block round that code (with the using block will be fine) and examine the Exception object that is caught in the debugger: it will contain more detail on exactly what the problem is. Without that, we are all just whistling in the dark.

The chances are that it's something pretty simple, like a field that is too big for the column you have allocated in the DB, or a unique value (such as a primary key) that isn't unique.

But until you get the message, and can look at exactly what data you are feeding into the parameters, nobody can tell.
And we can't do it for you: we don't have access to your DB, or the data you are feeding in.

BTW: the message box implies that you are storing passwords in clear text: if so, that is a Code Crime[^] and is a very, very bad idea. See here: Password Storage: How to do it.[^]
 
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