I have everything else setup but now i simply need to add an entry to my table in access.It would be simple to just show my data in a data grid view and use a binding source with a binding navigator, but i here is the scenario : I have to tables, One with Song Name , Artist and Genre and another table with only genre, the two tables have a relationship(with referential integrity) with relation to genre. I would like to call a inputbox in a C# program to simply add a new genre to the genre table. Now since there is no data grid view or any other control to easily add a entry, what is the simple procedure to add a entry into your table?
Here is my code thus far for the appropriate event handler :
private void newGenreToolStripMenuItem_Click(object sender, EventArgs e)
{
//(cnSongs)Connection delacred and instantiated elsewhere
cnSongs.Open();
string input = Interaction.InputBox("Genre ", "New Genre", "Type genre here", -1, -1);
string InsertSql = "INSERT INTO tblGenres (Genre) VALUES (" + input + ")";
OleDbCommand cmdInsert = new OleDbCommand(InsertSql, cnSongs);
//(daSongs)Data Adapter delacred and instantiated elsewhere
daSongs = new OleDbDataAdapter(InsertSql, cnSongs);
daSongs.InsertCommand = cmdInsert;
cmdInsert.ExecuteNonQuery();
cnSongs.Close();
}
I did research and only got the sql statement needed, which was useful but i need to know how to exacute it in code.
Thank you for your time.
daSongsare irrelevant (the comment saysdaSongsis instantiated elsewhere, clearly it is being instantiated right there). Secondly, you should learn how to useOleDbParameteras what you have is vulnerable to SQL injection. What problem are you seeing? Is there an error message?