|
You might want to have a look at this[^] series on Coding4Fun.
It'll save you having to write device drivers to get at the low-level details of a serial port, something that is abstracted from your code by Windows.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am trying to set sessions on the sql server in my web services. After running some scripts on sql server and setting the config files, how do I actually populate the sql server session tables? I would also like to save the data (from the user's search results) from several sessions in the session tables. Can somebody help me with this. Thanks.
Mina
|
|
|
|
|
i've selected some rows from the database and populate my DataSet.
After i've deleted some rows and update them.
Now i want to update the original Database with changed on the dataset.
i've used this code, but it is not good becouse it need an insert comand:
conn = new OleDbConnection(conn_string);
string selction_string = "Select * FROM myTable";
OleDbDataAdapter adapter = new OleDbDataAdapter(selction_string, conn);
conn.Open();
adapter.Update(mydataSet); <-----
conn.Close();
|
|
|
|
|
Yes, you need to provide the SQL to do the insert. What's wrong with that ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
so the dataAdapter doesn't understand automatically what is changed and make the correct update automatically?
If so, what is a possible SQL statement to do that (how have i to change the code)?
|
|
|
|
|
|
Honestly i don't wanted you to write code for me, but i want to know what is the correct InsertCommand i've to indicate for the dataAdapter.
I don't think it can be a: "INSERT INTO ..." becouse i don't know what are new rows inserted.
Then also rows deleted or modified.
|
|
|
|
|
Sasuko wrote: I don't think it can be a: "INSERT INTO ..." becouse i don't know what are new rows inserted.
It *has* to be INSERT INTO, what else would work ? The rows are marked in the dataset as being changed/added/deleted. I suspect if you provided SQL that selected specific columns, what you're doing may work, but like I said, I would iterate through the dataset myself and write a stored proc that takes XML and uses OPENXML to do bulk deleting/updating/inserting.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
so i've get all the row added to the datase then creating a SQL insert statement and past it to the datadapter?
|
|
|
|
|
You need to do what Wjousts said. I thought you did, but the sample I linked to didn't seem to have that bit, so I figured it could be inferred ( which makes sense, the table knows the columns, and it knows which rows are new ).
If the dataadapter works, then you wouldn't need to work out for yourself what rows are changed/new. I'm saying I don't use the dataadapter.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Of course it's INSERT INTO...
You need something like this:
MyDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO MyTable (MyField1, MyField2, ....) VALUES (?, ?, ...)",MyConnection);
MyDataAdapter.InsertCommand.Parameters.Add(new OleDbParameter("MyField1",int,0,"MyDataTableField1");
...
And so on. When you do the update the DataAdapter knows which rows are new and substitutes the parameters (the ? in the SQL statement) with the real values in your DataTable according to the mappings in the InsertCommands Parameters.
You might also want to do the Update and Delete commands as well if you actually want updates and deletes to be possible.
|
|
|
|
|
Hi All,
I want to developed application for automatically detecting Video format .can any one help regrding above problem.Pls do reply on frum or personally mail me .
Thanks & Regards,
Amit More
amit.more@pictureal.net
|
|
|
|
|
Reading the FOURCC-code from the header of the video will you give you a lot of information. You can then use a lookup-table to check agains the correct format.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I've created an application that use panels with image inside. i use these panels as custom buttons or just for graphic.
When the application start and these controls are drawed it appear for a bit black (during on paint event) then are drawed, it happen also if i use normal textbox xp style, they are black then became normal when the application is ended to load.
Why it happen to my application.
How can avoid it?
Please help me to understand where is the bug.
|
|
|
|
|
I think that that is a flicker...
You must enable double-buffering on your controls.
Put this in your constructor:
this.SetStyle ( ControlStyles.OptimizedDoubleBuffer, true );
this.SetStyle ( ControlStyles.AllPaintingInWmPaint, true );
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hello peoples,
I wonder if it is possible to create an instance of an object which type
is stored in a "System.Type" variable:
Example:
<br />
MyClass obj1 = new MyClass();<br />
System.Type type = obj1.GetType();<br />
((type) obj2) = new type();
I could write a huge "switch case" block and then switch through all
existing types, but it would be pretty inflexible and also bad style.
Any ideas ?
|
|
|
|
|
Activator class can help in your case
<br />
System.Type type = typeof(MyClass);<br />
MyClass obj = (MyClass)Activator.CreateInstance(type);<br />
DevIntelligence.com - My blog for .Net Developers
|
|
|
|
|
Hello tarasn,
the issue here is - I have to know the type(e.g. MyClass) on the left side of given expression and in the casting brakets too:
<br />
MyClass obj = (MyClass)Activator.CreateInstance(type);<br />
But in certain situations the type is unknown... Assuming I have to "unbox" an object of type "System.Object" and I also can get its Type using object.GetType() and store it in a variable:
<br />
System.Type type = object.GetType(); <br />
How can I create a new instance of whatever is boxed in this object?
Maybe some trick with StringBuilder or so...
-- modified at 10:38 Tuesday 17th January, 2006
|
|
|
|
|
Surely you cannot cast but you can still create the object:
System.Type type = object.GetType();<br />
object newObject = Activator.CreateInstance(type);
Note that this only works for objects whose classes define an constructor with no arguments.
|
|
|
|
|
Hi all,
I am calling excel macro function which is available in excel template file.
I get the reference of the work sheet, and iam trying to calling a macro from C#.The code is as below.
System.Diagnostics.Process[] myProcesses;
Excel.ApplicationClass appInstanceReference;
myProcesses = System.Diagnostics.Process.GetProcessesByName("EXCEL");
if ( myProcesses.Length > 0 )
{
Excel.Workbook xlwkbook = (Excel.Workbook) System.Runtime.InteropServices.Marshal.BindToMoniker(System.Windows.Forms.Application.StartupPath + @"\Templates\CommercialSizing.XLT");
if ( xlwkbook != null )
{
appInstanceReference = (Excel.ApplicationClass) xlwkbook.Application;
if ( appInstanceReference != null)
{
appInstanceReference.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, appInstanceReference,new object[]
{"'" + System.Windows.Forms.Application.StartupPath + @"\Templates\CommercialSizing.XLT" + "'!YourMacro"}
);
}
}
}
The problem is, it is not just calling macro function, instead of that, it is opening new excel template and it is calling macro function, but the excel sheet is already opened, i just need to execute my macro.what is the change i need to do in my code.Thanks for your help.
|
|
|
|
|
I have found one solution for how to color a row in a DataGrid based on the data in the row. Here's one example: guffy.net[^]. The problem is that it doesn't work when the DataGrid is sorted, or when a RowFilter is applied.
Example:
I have a simple table with two columns, one with integer values and one with strings.
15 Some text
-14 Different text
5 Another string
6 Yet another string
Say I want all rows where the integer is negative to have a blue background. This is easily done using the example above. In this example the second row will be colored blue.
But say I don't want to show any rows with an integer >= 10. When I create the DataGrid I use the code
DataView mainDataView = ((DataTable)this.mainDataGrid.DataSource).DefaultView;
mainDataView.RowFilter = "[Value] < 10";
Now the DataGrid will look like:
-14 Different text
5 Another string
6 Yet another string
But now the second row will have a blue background, instead of the first.
How can I solve this problem? Any help is appriciated!
(btw, I already asked this question in an old thread, but I'm new here and thought a thread would get "bumped" when it got a new message, turns out that the message bord is sorted by the first message in a thread, so I guess noone noticed that message...)
/Cesa
|
|
|
|
|
You should change these two lines
DataRowView v = (DataRowView)source.Current;
string curColumnValue = Convert.ToString(v.DataView.Table.Rows[rowNum][columnName]);
to
DataRowView v = (DataRowView)source.Current;
string curColumnValue = Convert.ToString(v.Row[columnName]);
A DataRowView knows its associated DataRow. Thus you don't have to look into the DataTable.
|
|
|
|
|
Thanks, but for some reason I can't get it to work. To be honest I didn't look into it that much since I managed to find another solution earlier.
I modified your example to my actual project:
DataRowView v = (DataRowView)source.Current;
DateTime date = (DateTime)v.Row["Date"];
...but it doesn't work.
This works fine though:
In class:
//public version of GetColumnValueAtRow
public object PublicGetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, System.Int32 rowNum)
{
return this.GetColumnValueAtRow(source, rowNum);
}
In Paint(...):
DateTime date = (DateTime)((MyDataGridTextBoxColumn)this.DataGridTableStyle.GridColumnStyles["Date"]).PublicGetColumnValueAtRow(source, rowNum);
-- modified at 12:46 Tuesday 17th January, 2006
|
|
|
|
|
Hi
i am working in c# with infragistics
In c# windows applicaion, I will be passing data from textbox..such that
for example:i haev 3 texboxes labeled
name:
age:
salary:....
Now name is the parent and age and salary r the child..so if i pass data in
the appropriate textbox..It should be added in the ultrawintree.......such that
name(parent) should show up on the root node of the tree. and age and
salary(child) should show up under the root node.
I did this as follows..
//ultrawintree
private Infragistics.Win.UltraWinTree.UltraTree ultraTree1;
//form load
private void Form1_Load(object sender, System.EventArgs e)
{
DataSet dataSet = new DataSet();
//read the schema
dataSet.ReadXmlSchema("..\\..\\Menu.xsd");//menu.xsd contains name, age and salary
dataSet.WriteXml("..\\..\\resultdata.xml",XmlWriteMode.WriteSchema);
}
//buttton click
private void button1_Click(object sender, System.EventArgs e)
{
DataSet dataSet = new DataSet();
// Read the existing xml
dataSet.ReadXml("..\\..\\resultdata.xml");
//name textbox----string type
string strName = txtName.Text;
//age text box----int type
string strage = txtAge.Text;
int intAge;
if (!strAge.Equals(string.Empty)) // check to make sure the user entered something
intAge = Convert.ToInt32(strAge);
//Salary textbox------int type
string strSalary = txtSalary.Text;
int intSalary;
if (!strSalary.Equals(string.Empty)) // check to make sure the user entered something
intSalary = Convert.ToInt32(strSalary);
//create a new row
DataRow newrow;
newrow = dataSet.Tables[0].NewRow();
// add new row.
newrow["Name"] = strName;
newrow["Age"] = strAge;
newrow["Salary"] = strSalary;
//add parent node in ultrawintree
Infragistics.Win.UltraWinTree.UltraTreeNode anode = new Infragistics.Win.UltraWinTree.UltraTreeNode();
//add parent node
anode.Text = txtName.Text;
//add child nodes
anode.Nodes.Add(txtAge.Text);
anode.Nodes.Add(txtSalary.Text);
anode.Expanded = true;
ultraTree1.Nodes.Add(anode);
//add the row to the dataset
dataSet.Tables[0].Rows.Add(newrow);
//write the data to a xml file
dataSet.WriteXml("..\\..\\resultdata.xml", XmlWriteMode.WriteSchema);
dataSet.AcceptChanges();
MessageBox.Show("Saved");
}
so now when i run this program, as it reads a xml schema and creates a xml file.. now when i clicked the button, it checks for teh xml file and each textbox
is binded to teh xml elements..so that the data which is passed in the xml file willbe added in teh xml..
now for example i gave john,22,1800 for name,age and salary respectively
it is added inthge xml..no when i give rex, 22,1700again adn when i cick the button..it shows that key already exists..key:22..
so please help met o add this..wht should i do to overcome this error
dhol
|
|
|
|
|
Is it possible to create a dialog represent .NET JIT dialog when application error?
Thank You.
|
|
|
|