private void btnadd_Click(object sender, EventArgs e)
{
try
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string foldername = folderBrowserDialog1.SelectedPath;
foreach (string st in Directory.GetFiles(foldername))
{
string filenme = st.Substring(st.LastIndexOf('\\') + 1);
pth = st;
dataGridView1.Rows.Add(filenme);
}
}
}
catch(Exception er)
{
MessageBox.Show(er.Message + "\n" + er.StackTrace);
}
}
private void btnsave_Click(object sender, EventArgs e)
{
MySqlConnection con;
con = new MySqlConnection(strpth);
try
{
con.Open();
MySqlCommand cmd;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
cmd = con.CreateCommand();
string col1 = dataGridView1.Rows[i].Cells[0].Value.ToString();
string str = col1;
string col2 = dataGridView1.Rows[i].Cells[1].Value.ToString();
string col3 = dataGridView1.Rows[i].Cells[2].Value.ToString();
string col4 = dataGridView1.Rows[i].Cells[3].Value.ToString();
string col5 = pth;
cmd.CommandText = "Insert into searchsong values('" + col1 + "','" + col2 + "','" + col3 + "','" + col4 + "','" + col5 + "')";
cmd.Parameters.AddWithValue("@File_Name", col1);
cmd.Parameters.AddWithValue("@Actor", col2);
cmd.Parameters.AddWithValue("@Music_Director", col3);
cmd.Parameters.AddWithValue("@Year", col4);
cmd.Parameters.AddWithValue("@Path", col5);
cmd.ExecuteNonQuery();
txtbxfilename.AutoCompleteMode = AutoCompleteMode.Suggest;
txtbxfilename.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtbxfilename.AutoCompleteCustomSource = namecollection;
}
}
catch (Exception ed)
{
MessageBox.Show(ed.Message + "\n" + ed.StackTrace);
}
finally
{
con.Close();
}
}