|
Hi Heath,
Ok really frustrated with trying to create a diffgram dataset.
I assume that I should first create a DataAdapter then build SqlCommand,InsertCommand, UpdateCommand for Adapter, Correct?
Next build parameters for each Commmand, Correct? After that I can then
Fill dataadapter, correct? Then I write my diffgram out to a file.
Does this sound like the correct approach to this?
After I do this I then take dataset and do inserts, updates etc. to
dataset. After done with this process I go back create a new dataadapter with whats mentioned above and call DataAdapter.Update.
What do you think? I did away with the webservice and have the create diffgram and database updates in a separate class.
Thanks,
JJ
|
|
|
|
|
To call Fill , you only need the SelectCommand set. When you call DataAdapter.Update , however, you may need all four set depending on what changes have been made. After calling Update , though, there will be no changes because the DataAdapter then calls AcceptChanges on your DataSet or DataTable (whichever you passed in).
So, you really only need to write out a DiffGram (if that's really necessary) after you make changes, otherwise those won't be any differences.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
See I need the diffgram because this is a pda app that is only sometimes connected to DB. So I need a way to record data to pda then update the database when a connection can be made. So I thought the diffgram would be the easiest way to accomplish this.
JJ
|
|
|
|
|
I was wondering if it was possible to import a comma delimited text file into a access database using c#? If someone could help me out that would be great.
Thanks.
|
|
|
|
|
Of course it's possible. Create an OleDbConnection to an MDB database file, then create an OleDbCommand from that with something like INSERT INTO MyTable VALUES(?, ?, ?, ...) for the CommandText . Then create an OleDbParameter for each ? .
Open the comma-delimited text file and split the strings on , (if you have other commas in the text, you'll need to do a little better job parsing taking quotes into account). For each line you read in and split, set the values of the OleDbParameter s you created above and call OleDbCommand.ExecuteNonQuery (after opening your connection for the batch, of course). When you're done, close the connection.
Read about the OleDbConnection , OleDbCommand , and OleDbParameter in the .NET Framework SDK. If you have specific question, please don't hesitate to ask.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How can I get the text in a DataGridTextBoxColumn to word wrap by default? The text just extends off the end of my DataGrid on a single line, even if I set the word wrap property of the Column's TextBox to true. If I select a TextBox for editing, then it wraps, but only while selected.
E. Simmons
|
|
|
|
|
The TextBox is only displayed when editing. When the text is displayed, it is simply drawn in the bounds and is clipped.
In order to word-wrap when displaying the text, you must extend DataGridTextBoxColumn and override Paint (the one with the most parameters, sine that's the one that's ultimately called) and GetMinimumHeight . When painting the string, make sure that StringFormatFlags.NoWrap is not set (negating the StringFormat.FormatFlags property with a bitwise AND), and set/unset anything else you want/don't want, including for other properties of the StringFormat .
The trick is that you have to use the Graphics object passed to Paint to call MeasureString , so that you can adjust the return value of GetMinimumHeight (since only enough for one line of text is displayed by default), but nothing that can't be done.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ahhhh, that works nicely. Thank you.
E. Simmons
|
|
|
|
|
The function in unmanaged DLL get char* as parametar. When I try to use that function with (out) string parametar, program breaks. How to use that function?
|
|
|
|
|
A char* is a string - they're both already pointers. So, don't use out or ref with a string unless you see an unmanaged declaration like char** or LPCSTR* or something.
BTW, if the string is actually a TCHAR* , TCHAR[] , or LP(C)TSTR , then make sure you specify CharSet.Auto . If the declaration is a char* or LP(C)STR , be sure to specify CharSet.Ansi since strings are Unicode in .NET natively. Both the DllImportAttribute and StructLayoutAttribute define a CharSet field you should set in the attribute in such a case.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If I pass only string as parametar program breaks with error message: "Object reference is not set to an instance of an object". Pass parremetar is char* type in dll.
|
|
|
|
|
And is the string set to something? Trust me, a char* is a string - in any language.
If the string is supposed to be an output parameter, do not use the out keyword but instead use the OutAttribute . This tells the marshaler that the parameter is an output parameter and will be assigned when the function returns.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If I understand you well, this is a solution for problem:
[DllImport("Kernel32.dll", CharSet=CharSet.Ansi)]
public static extern bool GetComputerName([Out,MarshalAs(UnmanagedType.LPTStr)] string f1, out int a2);
.
.
.
int v = 0;
string a = "";
if (GetComputerName(a, out v))
{
MessageBox.Show(a+" " + v);
}
But, this will not work???
|
|
|
|
|
You have that all wrong. The character set should be CharSet.Auto (since, like I said before, the string is LPTSTR ), and the second parameter is documented as [in, out], which means you should use ref because you MUST pass the size of the string buffer, which is probably why you're getting the error (not to mention the wrong character set when using Windows NT (4.0, 2000, XP, 2003). The property signature is:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool GetComputerName(string name, ref uint size);
uint size = 16;
string name = new string('\0', (int)size);
GetComputerName(name, ref size); You know what, though? You should browse the class library documentation and learn what's there. This P/Invocation is not necessary. Just use the Environment.MachineName property.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Why can't you remove it? How are you trying to remove it? Please be more specific or we really can't help you with your problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
its because i have no idea how to remove it!
i tried...
i have a xml document called Data!
string id = listBoxSpil.SelectedItem.ToString().Substring(0,2);
//the value of id is 1
XmlNode remove = Data.SelectSingleNode("//food[@id='" + id + "']")
Data.RemoveChild(remove);
But it doesn't work
so if you can tell me a way to remove it please help me!
|
|
|
|
|
First of all, make sure the id string is correct. When you call RemoveChild , you must call it on the XmlNode.ParentNode , because the XmlNode will most likely not be a child of the document (which only has one child - the root node, a.k.a. document element.
So, change Data.RemoveChild(remove ) to remove.ParentNode.RemoveChild(remove) and it should work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
heyY thanks man... it work now!!!
if there is anything i can do... just say it!
|
|
|
|
|
... But don't call me Sherly. I have a VS.NET 2002 project that uses a 1.1 Framework dll and it is giving me the StrongNameIdentityPermission error because it is looking at the MachineConfig for the 1.0 Framework. How do I get my project to the look at the 1.1 Framework Machine.Config?
|
|
|
|
|
You mean you have an assembly compiled with VS.NET 2002? VS.NET 2002 will only work with the .NET Framework 1.0.
In order to read from the machine.config file you want, mscoree.dll must load the appropriate CLR. This is determined by the assembly publishing policy or the runtime configuration in the .config file. This will only work at runtime however.
Read about the Runtime Settings Schema[^] in the .NET Framework SDK, as well as Redirecting Assembly Versions[^], which may or may not apply depending on what you're trying to do.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am using the Assembly.LoadFrom() method in my application to extract some information from some DLLs and I am running into a locking problem. Even after I am done with the file and have set the Assembly to null it keeps the file I loaded locked until the application terminates. The problem comes when I try and update the DLL with a new version automatically via the main application. I am unable to copy the newly downloaded version over because the file still reports as locked by Windows.
Does anyone know a way to tell the Assembly object to release it's hold on the file it loaded?
|
|
|
|
|
An assembly cannot be unloaded from an AppDomain . In order to make sure the file doesn't remained locked in use, however, you can read-in the file, grab the raw bytes, and load the buffer:
byte[] assembly;
using (FileStream fs = new FileStream(pathToAssembly, FileMode.Open,
FileAccess.Read, FileShare.Read))
assembly = new byte[fs.Length];
fs.Read(assembly, 0, assembly.Length);
fs.Close();
}
AppDomain.CurrentDomain.Load(assembly, null);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, that method works great.
|
|
|
|
|
I have implemented a code that runs at a Pocket PC 2002 platform. This is the client part , no problem. It saves some data such as names and adress information in XML document. The question is i want to send this data to a PC and upload necessary things. But i dont know how to start. the thing is just simple to upload XML file from PDA to PC or visa-versa. I couldn't find an article about this staff.if any one can tell me how to that or advises some article or site I will be glad. Thank you.
|
|
|
|
|
Hey Guys,
Here's the problem: I'm trying to learn multi-tier design so I've been writing a little app to teach myself. I have a normalised SQLServer database which contains my music collection. The DB schema is here[^].
So, I used LLBLGen[^] to generate a C# class for each of my table entities and that works great. There are SelectOne() and SelectAll() methods on each of my entities which allow you to select one record or the whole table.
My question is: how do I join the tables together? And how do I search them? I tried asking on the asp.net forums but they just suggested buying a OR mapper tool.
Cheers
James
|
|
|
|