|
I would have the person manually set the path for your app, as they may have their server set up where the server has the files on a remote computer.
|
|
|
|
|
I am lookinf for a way to insert data into Field codes in Ms Word from C#, I have been able to get it to open up the template and insert the data but i cant find anyway to insert it at the point where the codes are (it just places the text at the top)
Anybody know of a way to reference the Fields?
Cheers
|
|
|
|
|
how about invoking the find & replace method.
|
|
|
|
|
Hi! Im trying to create a form with a button that saves the output as a "text" file. My problem is that this code compiles without any exceptions however it tends to hang at runtime. Can someone please tell me what is wrong with my code and if i'm missing anything. The output is bound to a grid and shows a couple of data based on my drop down list.
private void btnSave_Click(object sender, System.EventArgs e)
{
OdbcConnection cnn = new OdbcConnection();
cnn.Open();
OdbcCommand cmmd = new OdbcCommand();
OdbcDataAdapter adp = new OdbcDataAdapter (cmmd);
DataTable dt_emp = new DataTable();
adp.Fill(dt_emp);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i=0;i<=dt_emp.Rows.Count - 1; i++)
{
for(int q=0;q<=dt_emp.Columns.Count - 1; q++)
{
sb.Append(dt_emp.Rows[i][q].ToString());
}
sb.Append(" ");
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=*.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";
System.IO.StringWriter strWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(strWrite);
Response.Write(sb.ToString());
}
dt_emp is the data passed. Thanx in advance for all your replies!!!
|
|
|
|
|
Have you put in a break point to see if it's just working ? How many rows/columns are we talking here ?
tatchung wrote:
i<=dt_emp.Rows.Count - 1
i < dt_emp.Rows.Count is surely more readable ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
yeah i did and it passes right by the whole function. i'm sure there's something wrong with it but i just can't figure out what. rows = depends on the result columns = 5 (but i still have to add 3-5 more columns; i cut the columns down just to see if it'll work. i'm just starting to learn c# by the way and all your comments, suggestions and even violent reactions could be of great help to me
thanx for all your replies!
|
|
|
|
|
tatchung wrote:
yeah i did and it passes right by the whole function.
Do you mean the click event does not fire, or do you mean that the rows/columns are 0 and so the loop is skipped ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
the click does not fire. it hangs at runtime. did i miss anything in my code or do you think its in the query to the database?
thanx
|
|
|
|
|
So where does it hang then ? If the click event does not fire, where does it go and hang ?
You need to set this function as the click event for your button in the aspx.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i did actualy. sori beating around the bush...whenever i click the save button the status bar on my browser hangs at 3 bars! it doesnt show anything at all and whats worse, my browser (internet explorer) crashes after a minute of hang time. dang i'm lost! that's what you get when newbies try out advanced stuffs. but i do appreciate your help! thanx a lot
thanx
|
|
|
|
|
OK - you've not done what I asked you then. If you're in debug mode, you can set a break point by placing the cursor on a line of code, and pressing F9. You can also right click and choose 'insert breakpoint'. Now your code will stop execution at this point, and you can view the state of variables, step through code, etc. The window to check variable state is on the bottom left, and you can use function keys or the Debug menu to step through. Now please do that, and check what values are being found, and why the loop is obviously not ending.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanx for the tutorial Chris! I hope Im not taking too much of your time. Well anyways I did what you told me to do and it stops at the 5th line of the code I posted; right on the cnn.Open(); . Now obviously the error is on the codes below it though how do i know what line needs to be fixed. I find my code logical...what do you think Chris?
thanx
|
|
|
|
|
Crap - how did I miss that ?
Yeah - debugging is great, especially at just working out exactly where the problem is.
The problem in this case is that you're not specifying a connection string, and so the connection object does not know what to connect to. I'm surprised it does not throw an exception, but it's obviously in the process of timing out, in utter confusion.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
isnt the OdbcConnection cnn = new OdbcConnection(); a connection string? im really sori if i sound too elementary to you guys. i learn fast though
thanx
|
|
|
|
|
No, a connection string is a text string that specifies the type of database, where it is, what it's called and how to connect to it. Your code is creating a new instance of a class used to connect to a database, but it does not know what database to connect to. What database are you using ? I suggest a google on OdbcConnection, assuming that you've got a database set up and ready to connect to. Also, if it's a SQL Server database, there are classes specifically for that ( although you still need a connection string ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hey! thanx for your help! i was so frustrated with the code i forgot that google IS our friend! i'l keep posting on inqueries again. thanx for all your help
thanx
|
|
|
|
|
|
What is you connection string?
... Or did you not have one??
> whoami
The system is unable to identify you when you don't even know your name!
|
|
|
|
|
He didn't have one the code he used is posted in a past relpy on this thread.
|
|
|
|
|
very perceptive expert but in case you didnt notice that was me (wowowee) who posted the previous code. and yeah i forgot to declare a connection string.
|
|
|
|
|
|
|
|
|