|
If you're using Framework 1.0 and VS.NET 2002, you'll need to download the ODBC.NET Data Provider[^].
If you're using Framework 1.1 and VS.NET 2003, then you just need to use the System.Data.Odbc namespace.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
|
|
|
|
|
Here's part of my project:
public class NetworkStats
{
private Form1 form;
private AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer player;
private ConfigResult cf;
public NetworkStats(Form1 form1, AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer player1, ConfigResult cf1)
{
form = form1;
player = player1;
cf = cf1;
}
public FileStruct FileStats()
{
string path;
DirectoryInfo dir;
FileStruct fs = new FileStruct();
path = cf.pathLog + "\\" + player.currentMedia.name + "\\";
dir = new DirectoryInfo(cf.pathLog);
dir.CreateSubdirectory(player.currentMedia.name);
if(cf.buffCount)
{
try
{
fs.fileStats = new FileStream(path + "Stats.txt", FileMode.Create, FileAccess.Write);
fs.swStats = new StreamWriter(fs.fileStats);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
if(cf.currBW)
{
try
{
fs.fileBW = new FileStream(path + "currBW.txt", FileMode.Create, FileAccess.Write);
fs.swBW = new StreamWriter(fs.fileBW);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
if(cf.currBR)
{
try
{
fs.fileBR = new FileStream(path + "currBR.txt", FileMode.Create, FileAccess.Write);
fs.swBR = new StreamWriter(fs.fileBR);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
if(cf.currFR)
{
try
{
fs.fileFR = new FileStream(path + "currFR.txt", FileMode.Create, FileAccess.Write);
fs.swFR = new StreamWriter(fs.fileFR);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return fs;
}
public void initStats()
{
FileStruct fs;
fs = FileStats();
while (Form1.videoParat != true)
{
try
{
form.BitRate.Text = (player.network.bitRate).ToString() + " Bps";
if(cf.currBR)
{
fs.swBR.WriteLine(player.network.bitRate.ToString() + " " + player.controls.currentPositionString);
}
form.BW.Text = (player.network.bandWidth).ToString() + " Bps";
if(cf.currBW)
{
fs.swBW.WriteLine(player.network.bandWidth.ToString() + " " + player.controls.currentPositionString);
}
form.buffCount.Text = (player.network.bufferingCount).ToString();
form.buffProgress.Text = (player.network.bufferingProgress).ToString();
form.buffTime.Text = (player.network.bufferingTime).ToString() + " mseg";
form.downProgress.Text = (player.network.downloadProgress).ToString() + " %";
form.currentFR.Text = (player.network.frameRate).ToString() + " FPS";
if(cf.currFR)
{
fs.swFR.WriteLine(player.network.frameRate.ToString() + " " + player.controls.currentPositionString);
}
form.encodFR.Text = (player.network.encodedFrameRate).ToString() + " FPS";
form.framesSkip.Text = (player.network.framesSkipped).ToString();
form.lostPackets.Text = (player.network.lostPackets).ToString();
form.rxQuality.Text = (player.network.receptionQuality).ToString();
form.sourceProtocol.Text = (player.network.sourceProtocol);
form.rxPackets.Text = (player.network.receivedPackets).ToString();
form.recoveredPackets.Text = (player.network.recoveredPackets).ToString();
form.maxBW.Text = (player.network.maxBandwidth).ToString() + " Bps";
fs.swStats.WriteLine("prova");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
//escriure la resta d'estadístiques
try
{
fs.swStats.WriteLine("prova 2"); <--------
fs.swBR.WriteLine("prova");
fs.swStats.WriteLine("prova 3");
fs.swBW.WriteLine("prova");
fs.swStats.WriteLine("Buffering Count: ");
}
catch (Exception e)
{
MessageBox.Show(e.Message);
Console.WriteLine(e.Message);
}
fs.Close();
}
}
public class FileStruct
{
public FileStream fileBW;
public StreamWriter swBW;
public FileStream fileBR;
public StreamWriter swBR;
public FileStream fileFR;
public StreamWriter swFR;
public FileStream fileStats;
public StreamWriter swStats;
public void Close()
{
try
{
swBW.Close();
swBR.Close();
swFR.Close();
swStats.Close();
fileBW.Close();
fileBR.Close();
fileFR.Close();
fileStats.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
The problem is that when arrives to "fs.swStats.WriteLine("prova 2");" it gets the "object reference..." exception, and I can't write anything to the output file....I really don't know what to do!!!
Please, if anyone has any idea, I'd be really grateful!!!!
|
|
|
|
|
Well, I would guess that, since you only create the swStats member when cf.buffCount is true, cf.buffCount is false.
Your best bet is to use the debugger to trace through your application. Check that swStats is being created properly, and if it is what else is happening as your app runs.
Also, I would define a new class that encapsulates the "create a filestream, create a stream writer" code. You're replicating it several times.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Thank you very much!! I think I've found the problem, although is not about cf.buffCount. You're right, I'll encapsulate this function into another class, thank you very much!
|
|
|
|
|
As title,
I am a C++ programmer so dont need a book that is too much geared for new programmers.
Are there any other books I should look at ?
I want to make use of the 50% off on this title at amazon.co.uk if it is any good
|
|
|
|
|
|
That link seems to point to "Help: Object reference not set to an instance of an object"
If it was meant to point to "Looking for a good book on C#", then I really want to know about C# Unleashed as it is enjoying a 50% off offer
|
|
|
|
|
Ooooops,sorry I don't know why the link does not work correctlly.there is another thread like your question 8 question below yours.Check it,I don't know why the link does not work.
Mazy
No sig. available now.
|
|
|
|
|
How can I add a type derived from DataGridColumnStyle into the list in the DataGridColumnStyle Collection Editor dialog box (of the Properties dialog box)?
|
|
|
|
|
I have a contextmenu which I use & for charachter to set shortcut for users. Foe example it has a "&Hello" test.The problem is an underline is shown in design mode under 'H' , but at run time it does not appear.The event habdler fires when I press H but there is no underlinw at run time.Any idea?
Mazy
No sig. available now.
|
|
|
|
|
You might have Windows' setting turned on where it doesn't show the accelerator letters unless you press Alt. An easy way to tell is to put a MainMenu on your form and do the same thing. If at runtime you don't see the accelerator letters then you know this is the case. Press Alt to bring up the menu and then they'll be there.
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing a medley of title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven".
|
|
|
|
|
Oh ya.When I press Alt they apear. Where is this setting in windows?
Mazy
No sig. available now.
|
|
|
|
|
On WinXP Pro it's located under Display Properties, Appearance tab, Effects... button, uncheck "Hide underlined letters for keyboard navigation until I press the Alt key".
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing a medley of title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven".
|
|
|
|
|
Thanks James.
Mazy
No sig. available now.
|
|
|
|
|
Scenario:
Typed Tables Earnings, Projects, Adresses, Einheiten
DataSets: EarnSet (Earnings, Projects, Einheiten), ProjectSet(Projects)
For one Programm I need the Tables Earnings and Projects in one DataSet. For another Programm I need just the Table Projects. The Status is that now I have two DataSets: EarnSet with Earnings and Projects Tables and ProjectSet with only the Projects Table. So I have the same table-Definition in two different DataSets.
Is there a way to add the typed Table Projects from ProjectSet to the typed DataSet EarnSet so that after in the EarnSet the typed! Table Projects exists?
Stefan
|
|
|
|
|
1. I think it's impossible to have one table into two datasets
2. Try to use one dataset or copy table with data
Hi,
AW
|
|
|
|
|
i have a number of projects located within my solution (they are dlls (3)) i reference the project from my main project,and when the dlls are compiled they are put in the directory with the .exe the program works fine...but i want to move those dlls to a diffrent sub folder (/data or something you know ?) but the .exe cant locate them if i move them. How can i move them and still have the .exe locate them ?
thanks for your time.
Jesse M.
The Code Project Is Your Friend...
|
|
|
|
|
I see people doing this with VB, but I can't get it to work in C#.
<br />
System.Drawing.Imaging.ImageCodecInfo myImageCodecInfo;<br />
System.Drawing.Imaging.Encoder myEncoder;<br />
System.Drawing.Imaging.EncoderParameter myEncoderParameter;<br />
System.Drawing.Imaging.EncoderParameters myEncoderParameters;<br />
<br />
myImageCodecInfo = GetEncoderInfo("image/tiff");<br />
<br />
myEncoder = new System.Drawing.Imaging.Encoder(System.Drawing.Imaging.Encoder.Compression.Guid);<br />
<br />
myEncoderParameters = new System.Drawing.Imaging.EncoderParameters(1);<br />
<br />
myEncoderParameter = new System.Drawing.Imaging.EncoderParameter(myEncoder,<br />
:confused:System.Drawing.Imaging.EncoderValue.CompressionCCITT3<br />
);<br />
<br />
myEncoderParameters.Param[0] = myEncoderParameter;<br />
DestBitmap.Save(strFileName, myImageCodecInfo, myEncoderParameters);
The compiler insists that it doesn't know how to convert CompressionCCITT3 to byte . I don't know why EncoderValue isn't one of the overloads in the first place. If I manually cast it as byte, int, or long, I get an invalid parameter error from save. Does anybody know which one of the 16 overloads I'm supposed to use?
|
|
|
|
|
I apparently lost track of all my permutations. byte, short, and int all result in "invalid parameter" from save, but long appears to work. I almost forgot that the int and long are the same thing in mc++ but not c#.
Thanks anyway.
|
|
|
|
|
I have a datagrid, dataset, and sql server data source. I would like to be able to update my dataset through my datagrid. I thought binding the dataset to the datagrid would give me the ability to do this, but I guess I am wrong (I am new to C# and .NET). I have created a dataAdapter to update the datasource, but I would like to update the dataset first. Can any one help me get started here. What I have is a datagrid and would like to allow the user to do update, insert, and delete data then click a button that will sync the datagrid with the dataset. Any insight is appreciated.
|
|
|
|
|
Binding a Control to a DataTable or DataSet adjusts only Data in the DataSet NOT in the SQL-Server Table. That means that your input in your Datagrid will only change Data in the DataSet. You have to Update the Tables with the DataAdapter.Update(DataTable) / SqlDataAdapter.Update(...) Method.
So your Button to Update: SqlDataAdapter.Update(DataTable) /DataSet
DataTable dt=new DataTable("Table1");
..
..
SqlDataAdapter ada=new SqlDataAdapter(...);
ada.Update(dt);
Be aware of not to call DataSet.AcceptChanges/DataTable.AcceptChanges() before DataAdapter.Update()! because otherwise no data will be updated; after AcceptChanges all Rows are marked as unchanged and so the DataAdapter don't "find" Rows to Update! In the help files everywhere you can find
"AcceptChanges()" which is very irritating.
|
|
|
|
|
Thanks for the response, but I realize that binding a control to a dataset will only update the dataset. The problem is after i bind to the control and update the datagrid.....the data in the dataset is not being modified. is there any code i need to implement to get the dataset updaated with the the data the user has modified in the datagrid?
|
|
|
|
|
Now I think I understand your question:
You modify data in the datagrid by typing in some new text, numbers...but the datasets data isn'nt changed which has nothing to do with the Sql-Server side datatables.
If a Control is bound to a dataset, the datasets data is changed when the user changes data in the control at once. That means that your binding code may be wrong. Would you like to show me your binding code?
|
|
|
|
|
Here is the code for my data binding. The form has a datagrid and two drop down lists. One of the lists allows the user to choose the table to modify and click a button to retrieve the data in that table. Therefore, when the form initially loads, I only bind it to the dataset and not a particular datatable. After the user chooses a datatable from the drop down list, I have an event handler that updates the data binding. Thanks for any help.
The code below is the initial data binding where the control is bound to only a dataset:
this.dataGrid1.SetDataBinding(todv.dvm, null)
I call another object that creates and manipulates a dataviewmanager (todv). todv.Filterview returns a dataview. So in this case, I bind to a dataview.
The event handler to update the databinding:
private void retrieveBtn_Click(object sender, System.EventArgs e)
{
string selectedItem = comboBox1.SelectedItem.ToString();
DataView dvm2 = todv.FilterView(comboBox2.Text.ToString(),comboBox1.Text.ToString());
dataGrid1.SetDataBinding(dvm2, null);
}
|
|
|
|
|
I think that dataGrid1.SetDataBinding(dvm2, null); is wrong.
try:
dataGrid1.DataSource=dvm2;
What method is FilterView?
|
|
|
|