|
If it is web application
Use Query String
Ex Reponse.Redirect("SecondPage.aspx?Param="+Param);
If it is windows application
add module and declare a varible in it assign a value and retrieve it in another page
I hope it ll help u
|
|
|
|
|
thank you for your help,
But i am working on a mobile application and it is not a web application.
I found finallay the solution for the problem.
It was very simple: add a parameter to the constructor of the form and call it with this parameter.
|
|
|
|
|
Hello
I am a beginner in programming in c #, I am trying to program a windows service that has as role of a PC scanner and collect information from WMI such as (disk space, machine name ...), and store these data in a SQLite database that I already create.I've managed to make the WMI connection and SQLite database but I wanted to know how do I do to store the results I get from WMI directly into my SQLite database.
Does anybody have an idea?
Thank you.
////////////connexion Wmi///////////////////
ConnectionOptions conop = new ConnectionOptions();
ObjectQuery query = new ObjectQuery("SELECT Name,Manufacturer,SerialNumber
from Win32_BaseBoard");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection queryCollection = searcher.Get();
///////////connexion sqlite////////////////////
using (DbConnection cnn = new SQLiteConnection("Data Source=import.db3"))
using (DbCommand cmd = cnn.CreateCommand())
{
cnn.Open();
cmd.CommandText = "CREATE TABLE carte_mére (Name VARCHAR(50),Manufacturer
VARCHAR(50),SerialNumber VARCHAR(50))";
cmd.ExecuteNonQuery();
foreach (ManagementObject m in queryCollection)
{
try
{
SQLiteDataAdapter adapter = new SQLiteDataAdapter(req,cnn);
adapter.InsertCommand = new SQLiteCommand("insert into carte_mére
Name,Manufacturer,SerialNumber values
(@Name,@Manufacturer,@SerialNumber)");
adapter.InsertCommand.Parameters.AddWithValue("@Name", d);
adapter.InsertCommand.Parameters.AddWithValue("@Manufacturer",
m.Properties["Manufacturer"].Value.ToString());
adapter.InsertCommand.Parameters.AddWithValue("@SerialNumber",
m.Properties["SerialNumber"].Value.ToString());
adapter.InsertCommand.ExecuteNonQuery();
} //Console.ReadLine();
catch (Exception)
{
Console.WriteLine("error");
}
|
|
|
|
|
Good Morning,
I work with Visual Studio2008.I create a listview.When running,the items appear in the same ligne and very near to each other.How can arrange their disposition to see them everyone in a ligne?
I do that but change nothing in my disposition:
.
.
.
if (dat.Tables["SQL Temp Table"].Rows.Count > 0)
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
ListViewItem item = new ListViewItem();
item.Text = dataRow[0].ToString() + "- " + dataRow[1].ToString();
listView1.Items.Add(item);
listView1.View = View.Details;
listView1.LabelEdit = true;
listView1.AllowColumnReorder = true;
listView1.CheckBoxes = true;
listView1.FullRowSelect = true;
listView1.GridLines = true;
listView1.Sorting = SortOrder.Ascending;
.
.
. }
This is the link of my image show of my problem http://yfrog.com/b6captureugwj
[^]
I wanna informe u that I work with Csharp smart device
Thanks
modified on Thursday, April 22, 2010 7:03 AM
|
|
|
|
|
|
I have created a data source (Access MDB file) runtime using following snippet:
CatalogClass cat = new CatalogClass();
cat.Create(connstr); // connstr: Connection string
It returns me a MDB file created.
I have a DataSet object with Tables shema defined in it...
I want to create a Table in MDB file with same table name and schema defined for DataSet.
I have tried following snippet to add table into data base:
cat.Tables.Append((object)table); // where 'table' is the ADOX.Table
It throws an Exception 'Column Id is invalid.'
System.Runtime.InteropServices.COMException (0x80040E11): Column ID is invalid.
How could I resolve it and will get data base schema created similar to the schema defined in DataSet?
|
|
|
|
|
You have to write some code to look at the schema in the DataSet and create each item seperately, building up the schema in the database. There is nothing in the .NET Framework that will create this stuff for you. That's not what the Schema stuff in the DataSet class was designed to do.
|
|
|
|
|
I have the following classes
[XmlRoot]
public class AList
{
public List<B> ListOfBs {get; set;}
}
public class B
{
public string BaseProperty {get; set;}
}
public class C : B
{
public string SomeProperty {get; set;}
}
public class Main
{
public static void Main(string[] args)
{
var aList = new AList();
aList.ListOfBs = new List<B>();
var c = new C { BaseProperty = "Base", SomeProperty = "Some" };
aList.ListOfBs.Add(c);
var type = typeof (AList);
var serializer = new XmlSerializer(type);
TextWriter w = new StringWriter();
serializer.Serialize(w, aList);
}
}
Now when I try to run the code I got an InvalidOperationException at last line saying that
The type XmlTest.C was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
I know that adding a [XmlInclude(typeof(C))] attribute with [XmlRoot] would solve the problem. But I want to achieve it dynamically. Because in my project class C is not known prior to loading. Class C is being loaded as a plugin, so it is not possible for me to add XmlInclude attribute there.
I tried also with
TypeDescriptor.AddAttributes(typeof(AList), new[] { new XmlIncludeAttribute(c.GetType()) });
before
var type = typeof (AList);
but no use. It is still giving the same exception.
Does any one have any idea on how to achieve it?
|
|
|
|
|
I have a tcp server that cooperates with a windows forms aplication. Now I have the following problem:
When I run it outside Visual Studio everything works just fine. But when I want to debug the application inside Visual Studio I get the message:
"Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on."
What can be the reason for this? Any suggestions?
|
|
|
|
|
Just put
CheckForIllegalCrossThreadCalls = false;
in the constructor of your main form in your Windows Application. It will solve the problem.
|
|
|
|
|
This is bad advice; it won't solve any problems, only mask them for a little while. The docs[^] state that illegal cross thread calls will throw exceptions when run outside of the debugger no matter what you do.
The correct way to perform cross thread UI operations is to invoke the operation on the GUI thread. See here[^].
|
|
|
|
|
Right.
|
|
|
|
|
Extremely bad advice
|
|
|
|
|
UI elements must be accessed on only the GUI thread. The Control class provides the Invoke /BeginInvoke methods to do this. See here[^] for a reference.
|
|
|
|
|
The 'solution' that was given first worked for me. Again my problem was only there when I was debugging in Visual Studio. Running the code in the normal way didn't pose any problems. So it seems to be only a VS issue!!
I will read the article that you described and see if something in the code has to be changed. Although I doubt that since I make use of delegates and that should take care of the thread issues.
Thanks for the feedback.
Regards,
Jan
|
|
|
|
|
jkpieters wrote: since I make use of delegates and that should take care of the thread issues.
Only if properly written using some form of Invoke. They are not a "guaranteed" solution to the problem.
jkpieters wrote: So it seems to be only a VS issue!!
No, it's not. If you enable the "CrossThreadCheck" property, you are not fixing the problem, nor all causes of it. You are mearly hiding the problem in certain situations.
|
|
|
|
|
It really doesn't matter if it's in or out of VS when it's running, if an app is throwing invalid cross-thread operation exceptions then it's not observing the "One GUI Thread" rule. The only reliable way to do so is to use the IvokeRequired/Invoke/BeginInvoke members of the Control class.
|
|
|
|
|
Ya you are right the solution is not advisable. I agree with you, but in this case as it was mentioned as a VS only problems during debugging that's why I have told him to do this. This will atleast allow your code to debug in VS. That's what he needed only.
But still it is not a good practice. Using of delegates is the good way to do it.
|
|
|
|
|
Hi,
I am trying to display 2 tables content in 2 DataGridViews on a single form. So i used 2 SQLDataAdaptor objects (for each table) and only 1 DataSet in which i selected both the tables during configuring. I wrote the following code:
sqlDataAdapter1.Fill(dataSet11);
sqlDataAdapter2.Fill(dataSet11);
dataGridView1.DataMember = "authors";
dataGridView2.DataMember = "publishers";
This code doesn't work. On running no data is displayed on the datagrids. If i set DataMember in DataGridView properties at design time then it works fine, but programmatically if i set, it does not work.
Please help me out!
Regards,
Priya.
|
|
|
|
|
try to set them manually after add COLs to each
EASY COME EASY GO
|
|
|
|
|
manually when i set in DataGridView DataMember property at design time it is working fine, but programatically it is not. Why is that?
|
|
|
|
|
sorry maybe i was not clear my self try this:
after you fill the dataset with database you can get each row with:
<code>
foreach(DataRow dr in DS.Tables[0].Rows)
{
DGV.Rows.Add(dr[0],dr[1],dr[2],dr[3]...);
}
</code>
but first you should add COLs
EASY COME EASY GO
|
|
|
|
|
how to add columns to datagrid? sorry i am new to this..
|
|
|
|
|
DGV.columns.Add("ID","ID");
DGV.columns.Add("Name","Name");
DGV.columns.Add("Note","Note");
EASY COME EASY GO
|
|
|
|
|
I am using the dbml file for database tables in the project .
My query is should i manually dispose these unmanaged objects whereever i use this class ?
|
|
|
|