|
is there any C# question here???
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
You should have right-clicked in the toolbox pane, and selected "Reset Toolbox".
I don't know how to fix your problem if uninstall doesn't work.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I'm trying to export data from my Sql server database to an excel spreadsheet using bulkCopy.The problem is that whenever i run my application throws "Format of the initialization string does not conform to specification starting at index 0" error.Whatam i doing wrong? Here is my code
public class CopyData
{
string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;";
string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";
public CopyData(string sourceConnectionString, string destinationConnectionString)
{
_sourceConnectionString = sourceConnectionString;
_destinationConnectionString = destinationConnectionString;
}
public void CopyTable(string StudentModule)
{
using (SqlConnection source = new SqlConnection(_sourceConnectionString))
{
string sql = string.Format("SELECT * FROM [{0}]", StudentModule);
SqlCommand command = new SqlCommand(sql, source);
source.Open();
SqlDataReader dr = command.ExecuteReader();
//IDataReader dr = command.ExecuteReader();
using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString))
{
copy.DestinationTableName = StudentModule;
copy.WriteToServer(dr);
}
}
}
}
i call this class under button export
|
|
|
|
|
That could only happen with the string.Format, but I cannot see anything wrong with it.
|
|
|
|
|
Never mind the first post from me. Misread the line.
Could it be this one:
Twyce wrote: string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";
Since you have @ before the string, you don't need to escape backslash (even though it's on a separate string).
Using debugger:
@"part1" + "\\part2" + "\\part3"
gives
"part1\\part2\\part3"
|
|
|
|
|
thanx for ur reply but i get the error when it gets to this line
using (SqlConnection source = new SqlConnection(_sourceConnectionString))
|
|
|
|
|
i think the problem is with my source connectionString
|
|
|
|
|
The problem would appear to be at the line
string sql = string.Format("SELECT * FROM [{0}]", StudentModule); Step over this line in the debugger and see what StudentModule contains.
|
|
|
|
|
thanx for ur reply.Thing is it throwsan error when the debugger gets to this line
using (SqlConnection source = new SqlConnection(_sourceConnectionString))
|
|
|
|
|
When you step over this line, what's in _sourceConnectionString? I ask this because you've initialised it to a value, and then you change it in the constructor.
|
|
|
|
|
What do you mean when you say I change it in the constructor?
The debugger does not even allo me to step over the line,it just keeps throwing the error
|
|
|
|
|
The following is your code:
public class CopyData
{
string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;";
string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";
public CopyData(string sourceConnectionString, string destinationConnectionString)
{
_sourceConnectionString = sourceConnectionString;
_destinationConnectionString = destinationConnectionString;
}
public void CopyTable(string StudentModule)
{
using (SqlConnection source = new SqlConnection(_sourceConnectionString))
{
string sql = string.Format("SELECT * FROM [{0}]", StudentModule);
SqlCommand command = new SqlCommand(sql, source);
source.Open();
SqlDataReader dr = command.ExecuteReader();
using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString))
{
copy.DestinationTableName = StudentModule;
copy.WriteToServer(dr);
}
}
}
} I've highlighted the line that changes the value. The code that creates this class is presumably doing something along the lines of CopyData c = new CopyData("connectionString", "destConnectionString");. Step into the CopyTable method and see what the value of _sourceConnectionString is before you execute the line
using (SqlConnection source = new SqlConnection(_sourceConnectionString))
|
|
|
|
|
it is not giving me a particular value just
_sourceConnection.sourceConnection
|
|
|
|
|
I think you're missing Pete's point. In the constructor you modify the value of the predefined _sourceConnectionString . Try adding the following message box:
...
public void CopyTable(string StudentModule){
System.Windows.Forms.MessageBox.Show("Going to connect to: " + _sourceConnectionString);
using (SqlConnection source = new SqlConnection(_sourceConnectionString))
{
... What is shown as the connection string that is used for connection? Is it what you would want ("Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;" ) or something else.
|
|
|
|
|
I want to use the Task Scheduler 2.0 lib for XP Home Edition when users have not setup an account. It seems the SetAccountInformation method, requires both a username and password. I believe there is a work around by changing registry values, although if I could I would love to avoid implementing that. Any thoughts?
I'm coding in C#
Bunis The Code Gladiator
|
|
|
|
|
If I have one form running, and I make another form, and call ShowDialog of the second form, the first form is locked. How could I open a second form so that the user can still use and manipulate the first form?
Thanks.
modified on Thursday, September 4, 2008 6:01 PM
|
|
|
|
|
use .Show() instead of ShowDialog()..
May be this solves your problem
Santhapur
|
|
|
|
|
|
Hi,
use child/parent forms method (child forms that load in a parent form).
That will solve your problems, need to type from the start
Check here in codeproject for articles
(i don´t recall link, sorry)
Good Luck
nelsonpaixao@yahoo.com.br
|
|
|
|
|
Up to now, I used a BizTalk Orchestration to find out when an application created a new file on a given path.
I think only for this feature what I need is BizTalk to expensive. The other requirements must programmed also with BizTalk.
Do you know open source tools for my intentions? A tool that gives me an information (whatever), when a new file is availabe. The tool must listen to a particular filepath.
In case of there is no tool available, I must write my own
Thanks for your help.
|
|
|
|
|
Forgive me for laughing out loud at the solution you choose. While biztalk offers this functionality it clearly is a case of putting a cannon to a fly. It just doesn't do the job right.
The right solution is right in the .NET Framework: FileSystemWatcher[^] class
|
|
|
|
|
Thanks for your answer.
Is it possible to watch one or more "fileshares" by an address such as \\servername\filesharename over the network with this class?
Only the listening of a local filepath, is not useful.
Thanks for your help.
|
|
|
|
|
Unfortunatly not, it only works for local file paths. Mapping the network path as a drive on the machine where the application runs and watching that should work also.
WM.
What about weapons of mass-construction?
"What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
My blog
|
|
|
|
|
Hi Wilem,
thanks for your great help. I have a last question.
My intention was to programme the application as an windows service for an e. g. Windows Server 2003. Are you sure, that the shares on this machine are furthermore available for the service when the user logged out?
I think no. But I don't know...
Thanks in advance.
|
|
|
|
|
Well if you let the service map the drive you should be good.
|
|
|
|