|
|
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 ?
|
|
|
|
|
What unmanaged objects are you talking about?
/ravi
|
|
|
|
|
I have an webbrowser control on my form. I am able display html files in that control. But my page contains some images if i give absolute path to it then images are displayed. But if i give relative path then images are not shown in the pages.
<br>I have HtmlPages folder located at bin folder.
<br>And i am assigning
FileStream source = new FileStream(@"..\HtmlPages\supportHtml.html", FileMode.Open, FileAccess.Read);
webBrowser.DocumentStream = source;
If i assign D:\myapp\bin\HtmlPages\file.png then there is no problem.
My images are stored in same folder. If i open html files with webbrowser then images are displayed.
What is the correct path to set ??
|
|
|
|
|
You're expecting that the application would load it's images from the same directory where your HTML-files are, as that's the way that it would work in a webserver.
I think that the application is looking in it's own "current directory", which is probably where the executable itself is located. My guess is that it will find the images if you put them there.
I are Troll
|
|
|
|
|
Hi,
by using webBrowser.DocumentStream = source; you are passing data to the WebBrowser without telling it where the data came from, so it cannot possibly use that location as its file base. Why don't you try webBrowser.Navigate(@"..\HtmlPages\supportHtml.html");
|
|
|
|