2
Answers

Error load audio from sql to Datagridview

toanhoi bui

toanhoi bui

13y
6.8k
1
I using C# to write a project to load file audio which formats .wav from SQL to DataGridView. But it was error .Can you help me,please ?

SqlConnection con = new SqlConnection("Data Source=CHANGEME1;AttachDbFilename=D:\\Code C#\\SimpleRec\\DataBase_Audio
  SqlCommand com = new SqlCommand("select *  from tbAudio where MaThe =136020379226", con);
  con.Open();
  DataTable dt = new DataTable();
  SqlDataReader dr = com.ExecuteReader();
  dt.Load(dr);
  if (dt.Rows.Count == 1)
  {
  dataGridView1.DataSource = dt;
  }
  dr.Close();
  con.Close();
  byte[] stream = (byte[])dt.Rows[0][0];

 
  File.WriteAllBytes("D:\\news.wma", stream);

Error is "The following exception occurred in the DataGridview"
Answers (2)