Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

Please can you give me the code that allows me to read a file.wav ("alarme.wav") stored in a database, I tried the following code:

private void button1_Click (object sender, EventArgs e)
{

OdbcConnection cn = new OdbcConnection ("DSN = cp1");
cn.Open ();
OdbcCommand cmd1 = new OdbcCommand ("select path from WHERE Code Alarm alarm = 32 ", cn);
cmd1.Connection = cn;
fileName = cmd1.ToString ();
WaveOut wave = new ();
wave.DeviceNumber = 0;
playSound (0);


But that gave me the following error:
"Could not find file 'C: \ Users \ wafa \ Documents \ Visual Studio 2010 \ Projects \ ALARMED \ ALARMED \ bin \ Debug \ System.Data.Odbc.OdbcCommand'."
At the line:
"waveReader = new NAudio.Wave.WaveFileReader (fileName);" in my "playSound" function:

public void PlaySound (int deviceNumber)
{
disposeWave ();// stop previous sounds Before Starting
waveReader = new NAudio.Wave.WaveFileReader (fileName);
var waveOut NAudio.Wave.WaveOut = new ();
waveOut.DeviceNumber = deviceNumber;
var output = waveOut;
output.Init (waveReader);
output.Play ();
}


Thank you in advance.
Good day:)
Posted
Updated 5-May-11 4:35am
v2

What are you doing?
This is wrong: fileName = cmd1.ToString ();

You need to run the query via command and then get the data back. From that data find the path and then use it to play the file.

You need to first read on how to use ADO.NET and then start coding for the same.
Read about ADO.NET here and it will help you.
Look at these:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]
The C# Station ADO.NET Tutorial[^]
Using ADO.NET for beginners[^]
 
Share this answer
 
Comments
Nicole castel 5-May-11 11:14am    
so how can i change this ligne please and thank you for the articls
Sandeep Mewara 5-May-11 11:17am    
Read how to use ADO.NET
1. Create connection
2. Create command - given query, open connection
3. Execute command, get data back
4. Use the returned data and find the file
5. Once file found, use/play it.
Nicole castel 5-May-11 11:25am    
Sorry I didn't understand how,I'm a beginner in Csharp and also and I didn't use Access before,so can you show me how to play my sound file so I can learn more my mistake
So ow can I change this ligne please?????????
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900