Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
C# - Submitting Windows form to SQLite database
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Stan Sypek
9y
613
1
Reply
I can use the following code to submit to a database on button click:
private void btn_add_Click(object sender, EventArgs e)
{
try
{
myConnection.Open();
SQLiteCommand myCommand = new SQLiteCommand(myConnection);
myCommand.CommandText = "Insert Into Person (FirstName,LastName,Email,Address,HomePhone,WorkPhone,MobilePhone) " +
"Values('" + txt_firstName.Text + "','" + txt_lastName.Text + "','" + txt_email.Text + "','" +
txt_address.Text + "','" + txt_homePhone.Text + "','" +
txt_workPhone.Text + "','" + txt_mobilePhone.Text + "')";
myCommand.ExecuteNonQuery();
myConnection.Close();
readData();
//MessageBox.Show("Your new data saved.");
txt_address.Text = "";
txt_email.Text = "";
txt_firstName.Text = "";
txt_homePhone.Text = "";
txt_lastName.Text = "";
txt_mobilePhone.Text = "";
txt_workPhone.Text = "";
}
catch (Exception)
{
throw;
}
}
This works fine as long as it is just text. I want a variation on this using text, radio buttons, and a combobox. All values should be saved to the database on button click. I'm using the code:
myConnection.Open();
SQLiteCommand myCommand = new SQLiteCommand(myConnection);
myCommand.CommandText = "Insert Into Albums (Artist,AlbumName,Year,CD,Cass,Vinyl,R2R,8Track,Genre) " +
"Values('" + txt_artistName.Text + "','" + txt_albumTitle.Text + "','" + txt_year.Text + "','" +
radbtnCD.Select + "','" + radbtnCass.Select + "','" + radbtnVinyl.Select + "','" +
radbtnRtoR.Select + "','" + radbtn8Trk.Select + "','" + combx_genre.Select + "')";
This gives the following error:
Operator '+' cannot be applied to operands of type 'string' and 'method group'. The error goes away if I remove all the components but the text. Can someone point me in the correct direction on how to mix the controls and submit them to the same database record? Thanks in advance.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Displaying user input into listbox
how to move a piece