|
I am trying to Insert Foreach statement
OleDbadpSource.Fill(dsSource, "Contacts");
string CNN = "id";
foreach (DataRow row in dsSource.Tables["Contacts$"].Rows)
{
OleDbcmdSource.CommandText = "INSERT INTO Address";
Items.Add(row["id"]); //I get an error "No overload for method 'Add' takes '1' arguments"
}
|
|
|
|
|
It means the Add method does not contain an Add() method which allows 1 argument.
What is the type of Items, I cannot find a declaration in your code... Maybe you need to add a few arguments in order to get it working...
|
|
|
|
|
Thanks for your prompt reply. I debugged that problem. Now the code works. However, the goal to create a foreach statement was to insert data from the dataset to the table in the SQL Server. Which has not yet taken place.
If you or anybody can help me with that. It will be very much appreciated.
|
|
|
|
|
Erhm, that's quite something your asking us. There are loads of ways to insert data into a database from any application. The first huge question is your application structure. If you use a neat n-tier app, your database are coded in a seperate project. However to get you going we'll implement the quickest way to insert data in your database, but keep in mind, though the code works, it's might not be a 'best practice' way to implement the functionality.
To implement a quick way to insert data into your database, create a SQL Insert statement. Therefore you need a stringbuilder which is the quickest for string manipulation.
StringBuilder sbInsert = new StringBuilder();
sbInsert.Append("INSERT INTO ");
sbInsert.Append("DatabaseTableName (");
sbInsert.Append("field, field, field, field"); // <-- Those fields are your database table column names
sbInsert.Append(") VALUES (");
sbInsert.Append("'Value 1',"); // <-- This the value in your database for the first field
sbInsert.Append("'Value 2',"); // <-- This the value in your database for the second field
sbInsert.Append("'Value 3',"); // <-- This the value in your database for the third field
sbInsert.Append("'Value 4'"); // <-- This the value in your database for the fourth field
sbInsert.Append(")");
Now you have the SQL statement, you'll only need to execute that query in your SQL Server. Therefore you'll need a SqlCommand object and a SqlConnection object.
SqlConnection sConn = null;
SqlCommand sComm = null;
try
{
using (sConn = new SqlConnection(ConnectionString[^]))
{
sComm = new SqlCommand(sbInsert.ToString(), sConn);
sConn.Open();
sComm.ExecuteNonQuery();
sConn.Close();
}
}
Catch (Exception ex)
{
MessageBox.Show(ex);
}
|
|
|
|
|
What about the pathname for the Excel data to upload on the server? Don't we need that in your above code??
strPath = Server.MapPath();
|
|
|
|
|
T4AMD wrote: What about the pathname for the Excel data to upload on the server? Don't we need that in your above code??
Who said anything about Excel? What does excel have to do with it?
-- Always write code as if the maintenance programmer were an axe murderer who knows where you live.
Upcoming FREE developer events:
* Glasgow: Agile in the Enterprise Vs. ISVs, Mock Objects, SQL Server CLR Integration, Reporting Services, db4o ...
* Reading: SQL Bits
My website
|
|
|
|
|
i put a message about use from gdtwain.beacuse i have a error:gdtwain.twainclass.twainclass() is in accessible deu to itsprotection level but is public.however i can't use twainclass please help me.thanks
|
|
|
|
|
Dear All,
Can we filter out the input char other than hexadecimal digits (0-9,A-F) by just setting the Mask string? If it's possible, please tell me how to do it. Many thanks in advance.
Cy
|
|
|
|
|
Check out the event KeyPress on maskedtextbox and use it.
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
Thanks, Rocky. With no doubt, a little programming is still needed.
|
|
|
|
|
I am trying to draw a set of lines within my application window that would show up as an overlay over the existing GUI controls (buttons with images on them)
I can draw the lines in the Form's on paint method, but the buttons are occluding them... is there a way to draw the lines after the buttons have been drawn so that the lines are not occluded?
I thought about using a transparent form that would sit on top of the other form and draw to that.. but I think that will stop me from being able to interact with the buttons..
does anyone know how to draw overlay stuff over controls?
I hope the answer is not to override the buttons on paint...as putting the code there just doesnt seem right.. the overlay is not part of the button objects..
Clear as mud, right?
James
|
|
|
|
|
Whatever else you do, if the button is invalidated, it will repaint itself. You could try using the CreateGraphics method to draw 'over' the buttons, and see if that works, but that definately gets voided when the control is invalidated, I'm just wondering if the main form gets the last say in that event cycle, so it's paint event might draw it again for you.
I'd have though you need to override the paint on the button.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I think the button has the last word there... as when I draw it in an overridden OnPaint method for the form.. the buttons occlude the lines.
I have not looked to see if the buttons are being invalidated unnecessarily. I will check that.
|
|
|
|
|
You are not the first to try this.
Have a look at Andrew Parsons story[^]
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for the tip.. he seems to be having the exact problem I am..
I like the idea of drawing to a tranparent panel as an overlay.. but I haven't been able to set up a transparent panel..
anyone have tips or tricks for this?
James
|
|
|
|
|
Transparent is not transparent. Setting the BackColor to transparent only tells the control to take on the background settings of its parent container, usually the Form. So, if the form is gray, the background of the Panel will be gray. You can't actually "see through" a "transparent" panel.
|
|
|
|
|
I want to process lines of a .Doc ms-word file in c#.net,I have searched in MSDN but it didn't help.If any one give me a hint OR name of right term to search in MSDN or internet, please?
Regards
M.Neishaboori
|
|
|
|
|
Hi,
for Office 2003 and higher, there is a downloadable "Office PIA" (Primary
Interop Assembly)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
In addition to what Luc said, I believe the PIA only work if Word is installed on the machine that runs your code, but the new docx format is just a zip file with XML in it, so if you work on the new docx format, it's probably a lot easier to get to where you want to be.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
In addition to Luc and Christain :P
If you are using older version of Word you'll need to delve into the wonderful world of Structed Storage files, also known as Compound Documents (because having one name would be too easy).
Doing searchs on stuff like "c# structured storage" should give you code for handling these files and a search like "word file format" should through up sites where they have reverse engineered the format so you can tell what property 80010125 is :P
|
|
|
|
|
Hi,
Thank you all guys.I'll keep try!
M.Neishaboori
|
|
|
|
|
I've programmed a button, called 'Remove' to delete items, by counting the amount of selections, and than by a for-loop, doing listbox.remove, and when the loop is done, all selected items were deleted. But it just doesn't seem so userfriendly with this button.
Does listbox have something simple that allows the delete-key the do the same as the remove-method? Or should I be thinking in terms of making an event for listbox, and check if the 'DEL'-key was pressed, and then execute the same code as with my button?
Thanks in advance
|
|
|
|
|
Hi,
I would use ListBox.KeyDown event and a foreach loop over ListBox.SelectedItems
to call ListBox.Remove
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I can't delete it as it has been answered....
Hi - gone totally blank on this, up against the clock, and hoping somebody can patronisingly explain this one...
I have a Button on a webpage, which when clicked, generates a word doc, via automation, and saves it to a share. All done server side. Code simlar to the following (which doesn't work):-
protected void OnGenerateDoc( object sender , EventArgs args )
{
MyDocGen gen = new MyDocGen();
gen.CreateDocAndSaveHere(@"\\publicserver\publicshare\wellknownfilename.doc");
(HttpContext.Current.CurrentHandler as Page).ClientScript.RegisterClientScriptBlock(this.GetType()
, "myScriptKey", "alert('your document is ready');");
}
The alert command should be any javascript function that can be called. I just want it called when my stuff is complete. Any ideas? This is all in a custom control, in a DLL , hence the long winded way to get to the ClientScript . Is this the correct way of getting a reference to the page? Last modified: 54mins after originally posted --
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
Malcolm, I don't know the answer, but it sounds a lot like a web-development specific question. Have you tried asking this in the ASP.NET forum[^]?
|
|
|
|