Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
When I tries to insert data to sqlite in window store app it gives unexpected exception in SQLite.cs file. My code looks like:-
SQLiteConnection con = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "Fav.db"));
favorities addData = new favorities();
addData.Name = Title.Text;
addData.desciption = desciption.Text;
con.Insert(addData);`
and when I click on button on which these operation are being performed run time exception arises which looks like:-
in fact this SQLite.cs file is an API which I downloaded from "Manage Nuget Package" please help me out.
Thanks & Regards,
The table doesn't exist in the database.
Use this after you create the extension:
con.CreateTable<favorities>();
The creation of the connection would be better in a using statement too.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
System.Data.SqlClient.SqlException: 'Could not find stored procedure 'Core.SetContextInfo'.'
This procedure is present in my database all connection look fine but not sure why I am getting this error. I am not able to access application and when I debug I found this error.
When you get this error, it is probably because of not using correct name of database or schema before the name of stored procedure. I suggest you use fullname of stored procedure with the name of database and schema (if you have one) before your stored procedure name.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Before I ask the question I just want to say that I have gone through a lot of other similar questions like this and they didn't help that's why i decided to ask mine.
Ok, so I'm trying to upload a selected image to the database when an Upload button is clicked, the front-end was written in ASP.NET and the back-end in C#.
This is my code:
if (FileUpload1.HasFile)
{
SqlConnection con = new SqlConnection("i put my connection string here");
con.Open();
int length = FileUpload1.PostedFile.ContentLength;
byte[] pic = new byte[length];
FileUpload1.PostedFile.InputStream.Read(pic, 0, length);
SqlCommand com = new SqlCommand("insert into LogHelp (file) values (#image)", con);
com.Parameters.AddWithValue("#image", pic);
com.ExecuteNonQuery();
con.close();
}
Now I'm using Visual Studio 2015 web form. When I run the code above, it throws this error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Incorrect syntax near the keyword 'file'.
Please what exactly does this mean? And if you have another way I can use to accomplish the same task please I'm all ears.
I've since tested the hypothesis I put forward in my comment:
You need to surround your file with square brackets - FILE is a keyword in SQLServer
insert into LogHelp([file]) values(#image)
I disagree with the other commenter; I'm of the opinion that no database system I've used needs to have a space between the end of a table name and the opening bracket listing the columns to insert into. I do, however concur with his observation that there is no need to write the SQL as two strings that are concatenated ("INSERT..."+" values...") in your code though
Consider NOT getting into the AddWithValue habit, for reasons set out here: https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to cause a database validation error when inserting into (or editing) the database to test the try/catch
C# is too smart and catches my type casting errors.
Try inserting a value that doesn't fit into a column (a string 10 characters long in a varchar(2)),
reference a foreign key that does not exist,
a null value in a column that doesn't accept nulls,
try connecting to the database with the wrong password/user combination.
Without any sql/c# code it's hard to know how you have things setup
EDIT- answer in comments:
"do you have any identity fields? try inserting a value that already exists into that column"
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Found this csv parser: https://github.com/bytefish/TinyCsvParser
Following his example but I even added one int property.
By setting a negative value to that int, it gave me one unvalid row.
Couldn't find any solution for this simple? problem.
The type converter was using the wrong NumberStyle as default. I have fixed the problem and added a Test case to the project: https://github.com/bytefish/TinyCsvParser/issues/2.
You could also instantiate a custom converter with the right NumberStyle (see WithCustomConverter, Example), but I suggest simply updating to the latest version (0.6), which is also updated in NuGet.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to make a C# (Windows Forms) application which utilizes SQLite. Anyway, my code is this :
try
{
db.Insert("COLUMN_NAME", data);
}
catch (Exception e)
{
//MessageBox.Show(e.Message);
}
I made COLUMN_NAME unique, so it throws an SQL error, intentionally. But I don't want to see the error message in a MessageBox, so I commented out the MessageBox.Show() line, but still the error message pops up. Is it a property of try / catch ? If so, how can I prevent it ?
P.S.
I know there are better ways to do this task, but it is not important. I just want to learn how to get rid of error messages in exceptions.
Thanks for any help !
I figured the problem. The line db.Insert(); itself has a try/catch block, which shows a MessageBox.
I found the code here by the way.
Thanks again for all the help !
There is RunTime error in your line at
db.Insert("COLUMN_NAME", data);
So you need to fix this.
Try by clean and then build your code. Then run the code. Sometimes dll file is not refreshed. It will be regeneratedby clean and build your code.