|
public static SqlDataAdapter CreateSqlDataAdapter(SqlConnection connection)
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
adapter.SelectCommand = new SqlCommand(
"SELECT CustomerID, CompanyName FROM CUSTOMERS", connection);
adapter.InsertCommand = new SqlCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (@CustomerID, @CompanyName)", connection);
adapter.UpdateCommand = new SqlCommand(
"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " +
"WHERE CustomerID = @oldCustomerID", connection);
adapter.DeleteCommand = new SqlCommand(
"DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);
adapter.InsertCommand.Parameters.Add("@CustomerID",
SqlDbType.Char, 5, "CustomerID");
adapter.InsertCommand.Parameters.Add("@CompanyName",
SqlDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@CustomerID",
SqlDbType.Char, 5, "CustomerID");
adapter.UpdateCommand.Parameters.Add("@CompanyName",
SqlDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;
adapter.DeleteCommand.Parameters.Add("@CustomerID",
SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original;
return adapter;
}
The above function returns adapter of SqlDataAdapter type. Could anyone suggest on how to use it for InsertCommand, UpdateCommand and DeleteCommand in some other place.
|
|
|
|
|
praveen.code999 wrote: how to use it for InsertCommand, UpdateCommand and DeleteCommand in some other place.
Do you want an option to specify the command which has to be created instead of creating all three?
|
|
|
|
|
Hi All,
I am facing very strange problem. I have a Windows form and there are two buttons on it. Each has its click event as shown below:
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Button 2 CLICKED");
}
private void button1_Click(object sender, EventArgs e)
{
button2.Enabled = false;
long = 0;
while (i < 999999999)
{
i++;
}
button2.Enabled = true;
}
on the click of button1, i am disabling button2 and then do some processing (loop) and then enable the button2 again.
Problem is that when i click button1, button2 gets disabled and now i click on disabled button button2, wait till it become enable, at the moment it become enable, its click event gets fired and Message "Buuton 2 Clicked" displayed.
How does C# allow events on disabled buttons?
Please let me know, am i doing something wrong?
Naveen
|
|
|
|
|
Couldn't find much info on this, except that clicks are queued, so when the button becomes enabled, it will fire as many times as it was clicked when disabled. Lame.
One way around it would be to create a 3rd dummy button that's exactly the same as the 2nd button. Then, instead of disabling the second button, hide it and show the 3rd button (disabled). When you're done processing, hide the 3rd button and show the 2nd button again. That way all the clicks will be on the 3rd button, which you can just discard or not even write a handler for.
Did that make sense?
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
Thanks for reply,
But i think this would not work for me as i have to enable/disable so many buttons. I told only 2 buttons just to describe problem.
|
|
|
|
|
When button1 is clicked, you are disabling button2 and starting a long running loop. This loop is running on the main thread where your UI elements are hosted. So it blocks all the messages passed to the window until your loop finishes. The click message is delivering to the window only after loop is finished and button is enabled. It processes the event and you get message. This is how it works.
As a workaround for this, you can run the long running loop on a separate thread. Here is a sample
button2.Enabled = false;
new System.Threading.Thread(delegate(object obj)
{
long i = 0;
while (i < 999999999){
i++;
}
this.Invoke((MethodInvoker)delegate { button2.Enabled = true; });
}).Start();
|
|
|
|
|
Hello,
Please do you know of any C# wrapper for the path functions in shlwapi.dll out there?
I will have to write one, but there is one ready for use, I will not mind.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
I got this[^] from pinvoke.net. is that the one you are looking for?
|
|
|
|
|
Thank you very much, not complete but a good start.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
when i am using NativeMethods, then i am seeing fallowing error : NativeMethods is inaccesible due to its protection lavel.
Am i missing any assambly reference?.
amit
|
|
|
|
|
Where did you find the NativeMethods?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
if you've trying to use NativeMethods from BLC then you're getting the error correctly for all of those are marked as "internal". Hence you can't access them directly.
You can always cheat and use Reflection or simply cut n'paste the code from the Reflector....
|
|
|
|
|
Hi,
I am getting the error System.StackOverFlowException while reading the data from Comm port what is the reason can anybody tell
|
|
|
|
|
Try checking your call stack in the debugger. Are you calling a recursive function anywhere? Stack overflow often occurs when you fail to hit the base case of a recursive function.
Dybs
|
|
|
|
|
Hi I am getting this error when I am taking the data from the Serial port for emmbedded application on one system it is working fine but on other it gives error while recieving data from the comm port when the data recieved function is called the error is System.StackOverflow
Thanks,
kanwal
|
|
|
|
|
The following code is supposed to be comparing two datasets and then load the rows that are not duplicates into a third datatable.Instead it repeats the rows that are already in the database(making more duplicates).Could someone tell me what i am doing wrong.
foreach (DataRow parentrow in dsImport.Tables[2].Rows)
{
DataRow[] childrows = parentrow.GetChildRows(r);
if (childrows == null || childrows.Length == 0)
dtImport.LoadDataRow(parentrow.ItemArray, true);
}
foreach (DataRow databaseRow in dsImport.Tables["StudentModule"].Rows)
{
foreach (DataRow spreadRow in dsImport.Tables["Sheet1$"].Rows)
{
if (spreadRow != databaseRow)
{
dtImport.BeginLoadData();
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return dtImport
|
|
|
|
|
first off, PLEASE use pre tags for code blocks...
second, why not create primary or unique keys on your datatables? that should help with the duplicates
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Hi,
I'm trying to build a dll that makes automated changes to powerpoint presentations. I want to go through each slide and change all instances of an automatically generated date/time to one that I will provide. I'm having trouble finding in in the object model, however. I've gotten all the way to the slide.shape.textframe how can I check to see if what is in the frame is an automatically generated date/time?
I was thinking maybe text fields store a collection of objects taht aren't necessarily text and I could test against a dateAndTime object or something, but it looks like this is not the case.
Any Suggestions?
|
|
|
|
|
hi every body
i want know how can i get the path of the folder which the program start from it after install
example
the default directory for any program is :
c:\program files\*****\****
but user may change this path to any another path
my question is how can i get this path
i have tried (Environment.CurrentDirectory);
but it didn`t work
it returned by (My documents path)
any body can help me ??
|
|
|
|
|
Application.StartupPath works under most situations.
Environment.CurrentDirectory only gets the current working directory - nothing to do with the application itself.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
thank you davey it`s worked with me
|
|
|
|
|
hi,
i want to use my java classes in c# application.I used IKVm tool which will convert java class files to dll.But my one of the class is giving me error when i am using it.Error occurs when i create object of that class and in that class there is one more class called.And it will give me error that class not found.i also included the reference for that second class in my C# project.
If anybody can help me that will be great.
Thanks in advance.
From,
Monika.
|
|
|
|
|
Hallo all, I'm using c# to load an rtf file in a richTextBox but I have a problem when the file includes table of contents (TOC). The TOC appears as plain text, while in ms word it has blue fore color, and if you press it (in ms word "control button and click") it does not respond at all.
Is there a way to use the TOC in richTextBox??
Thanks!!
|
|
|
|
|
Nope. Not supported. RichTextBox does not contain a complete implementation of RTF. Also, Word offers features that you don't find in the RTF specification.
|
|
|
|
|
I am trying to translate some extended characters back into a more "English" representation, so that users can more easily search for the strings in a database.
For example, the singer "Beyoncé" has a "e" with a symbol over it and we use this representation for the display name. This symbol can be entered by typing alt+130 on the numeric keypad. However, we also want to store the "normal" version of the string ("beyonce") in a second field, so that we can search for it without having to jump through hoops. We want to automatically generate the search name based on the text in the display name field.
I've tried messing around with string replacements, lookup tables and other esoteric mechanisms, but nothing seems to work consistently. I'm now thinking I need to start looking at code pages and different encoding mechanisms, but the documentation on this is so terrible, it's difficult to know where to begin.
Does anyone know of a reliable, platform-independet method to remove these extended characters and replace them with a suitable English equivalent? Additionally, is there a better way of entering these characters, other than the alt+numpad mechanism, which also seems to change depending on code pages and other witchcraft.
eg:
Beyoncé --> beyonce
Mötley Crüe --> motley crue
Thanks!
|
|
|
|