|
snayler0 wrote: sorry for all the try/catch's. been using them to try and pinpoint the error and the error message.
Do you know how to use a debugger?
try
{
command = new SqlCommand("SELECT * FROM Key", con);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
command = new SqlCommand("SELECT * FROM Key", con);
}
If the first time you tried creating the command threw an exception, why do you think trying it again won't do the same thing?
It would be more help you just looked at line 89, or told us which line it was.
only two letters away from being an asset
|
|
|
|
|
yeah, lol sorry bout that.
i had already found that line to not be causing any problems, but because command was being defined locally in the try block, it wasnt accepting it further down, because there was a chance it would be undefined (if there was an exception) and wouldn't compile because of it. so i just threw them i nthe catch as well since i knew those particular parts were working, (instead of doing away with the try/catch's for those parts alltogether)
the only place an exception is coming up from is:
try
{
da.Fill(dt);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
|
|
|
|
|
after removing all the try/catch's that weren't needed anymore, i have recieved a different error (on the same line ( da.Fill(dt); )
the error is now SQL specific... but i think my syntax looks fine.. be prepared... its a long error message, here it is:
Error: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'Key'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Keystore.FindKey.FindKey_Load(Object sender, EventArgs e) in C:\Users\Shane\Documents\Visual Studio 2008\Projects\Keystore1\Keystore1\FindKey.cs:line 46
|
|
|
|
|
Yup your datatable dt is null.
datatable dt = new Datatable();
|
|
|
|
|
Thanks for that, i hadnt noticed.
ive changed it to
dt = new DataTable("AllKeys");
since this table should be filling with all the keys in the database.
But i am still getting the error mentioned in my previous post.
it doesnt like the syntax of
command = new SqlCommand("SELECT * FROM Key", con); near the keyword 'Key'.
it isnt picking up this error until i try to execute the line:
da.Fill(dt);
|
|
|
|
|
the word 'Key' is a keyword in SQL Server and should not be used as an object name. You could enclose it in [] but it is best to change the name of your table (as you have found). The following will work but is not recommended.
command = new SqlCommand("SELECT * FROM [Key]", con);
If you have SQL Server Management Studio (SSMS), test your scripts in SSMS before implementing in VS, you will get much better information and feedback from SSMS.
|
|
|
|
|
I am currently studying XNA.
Is there any convenient way to recognize mouse gesture?
For example, how to tell whether I have draw a circle clockwise.
|
|
|
|
|
There's nothing specific in XNA over regular C#. There's an example here[] you could look at
|
|
|
|
|
I am sorry. Which example?
|
|
|
|
|
Sorry, looks like the forum ate my link!
http://www.codeproject.com/KB/recipes/cmgblade.aspx
|
|
|
|
|
I'm writing a small telnet-based app that connects to a *nix box, executes some commands and displays the output. When the user is logged on, several scripts run requiring user input and the set of scripts are different for each box (so I can't just hardcode responses).
It seems like the best solution is to break out of the scripts and do their work myself but I can't figure out how to send the Ctrl-C character to do this. Any ideas?
|
|
|
|
|
Character 3 -- but I suggest you try communicating with the scripts properly. I've written code that automates a Telnet session; what problem are you having?
|
|
|
|
|
Primarily I was hoping to create a GUI application that required no user input other than hostname, username and password. We deal with different flavors of *nix, and each one reacts to commands slightly differently, plus these login scripts can be different on each machine.
Essentially, since I know what all the settings to should be, I figured it was easier just to break out of the scripts and set the environments myself rather than deal with all the parsing necessary but I realize that's me being a bit lazy .
|
|
|
|
|
zenlc2000 wrote: create a GUI application that required no user input other than hostname, username and password.
What's the point?
I had to write a Windows Service (therefore no user input, just configuration) to interact with a character-based third-party product on SCO Unix.
I wrote my own simple scripting language to do it. I expect a similar technique could be used in your situation.
|
|
|
|
|
Hi,
Hi,
Looking at the xml data below I would like to retrieve the values in <mopkelid> and <mopvalue>
1-
How is this done please?
At present I am using xmlDocument with loops but can not get these values?
Thanks
<main>
<version>1</version>
<somedata>
<data1>1</data1>
<data2>2</data2>
...
...
<data3>
<value>
<value>more data</value>
</value>
</data3>
...
<superset>
<kelid>
<mapping>
<mopkelid>figure1</mopkelid>
<mopvalue>another figure</mopvalue>
</mapping>
<mapping>
<mopkelid>figure2</mopkelid>
<mopvalue>something else figure</mopvalue>
</mapping>
...
...
</kelid>
<kelid>
<mapping>
<mopkelid>figurex</mopkelid>
<mopvalue>another figure x</mopvalue>
</mapping>
<mapping>
<mopkelid>figurey</mopkelid>
<mopvalue>something else figure y</mopvalue>
</mapping>
...
...
</kelid>
</superset>
...
</somedata>
|
|
|
|
|
Please stop asking elementary questions like that; if you are not familiar with some technology and want to learn, then do some research, read a book, read some articles, and use google; don't expect the world to spoon feed you all the time.
People on this site are more than willing to answer specific questions once you show you made an effort; this isn't elementary school.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi,
This is what I have now:
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
// Retrieve all prices.
XmlNodeList nodeList = doc.GetElementsByTagName("mopkelid");
foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "figure1")
{
Console.WriteLine(node.ChildNodes[0].Value);
}
}
Question:
I would like to find all occurances of figure1 in any elelemnt which is called
<mopkelid>
see my xml example in the earlier post.
Thanks
|
|
|
|
|
You seem to have missed this[^].
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
All I can say is that after searching I have managed to write the code I showed before and need help extending that code.
Any way, thank you for your time.
|
|
|
|
|
Here is a hint, XPath. Now go away and do as Luc has suggested.
only two letters away from being an asset
|
|
|
|
|
|
What I would like to do is instead of manually parsing for each table and row. I would like to learn how to do a foreach to dynamically find each table and each row in a database. Here is what I curently have, All I am asking is how to use the foreach command to do this.
1) How would you say:
foreach(table in database)
then how would you say
foreach(row in table)
New experimental project I am playing with. I will post back when I find something. Just thought I would ask.
string sConnectString = "Driver={QODBC Driver for QuickBooks};DFQ=C:\\Quickbooks\\sample_company_file.qbw;OpenMode=M;OLE DB Services=-2;";
string sSQL = "SELECT Name FROM Employee";
OdbcConnection cn;
OdbcCommand cmd;
cn = new OdbcConnection(sConnectString);
cmd =new OdbcCommand(sSQL,cn);
try
{
cn.Open();
MessageBox.Show("open");
OdbcDataReader dr = cmd.ExecuteReader();
dr.GetSchemaTable().
MessageBox.Show(dr.GetSchemaTable().TableName);
}
catch (OdbcException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
|
|
|
|
|
Hi,
1.
obviously you get all rows in a table by selecting everything as in "SELECT * FROM tablename", so just skip the WHERE clause.
2.
how you get information on the tables themselves probably depends on the database; in MySQL it simply is "SHOW TABLES"
Look in the documentation for your database!
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
JollyMansArt wrote: 1) How would you say:
foreach(table in database)
then how would you say
foreach(row in table)
foreach is not a realy usable construct for examining database tables, I would normally use
reader = sqlCmd.ExecuteReader();
while (reader.Read())
{
...
}
Think about it: if you were dealing with a file, you would say:
string[] lines = inFile.ReadAllLines();
foreach(string s in lines)
{
...
}
rather than trying:
foreach(LineOfText line in inFile)
{
...
}
You can't use foreach for the columns, either - there isn't an Items collection - but even if you could, it really wouldn't be too helpfull:
foreach(var v in reader.Items)
{
... Workout what type it is and what to do with it...
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi
I have a datagridview (in a windows application) which its data comes from executing a StoredProcedure. This SP joins two tables and derives the data needed.
what is the role of dataview in inserting a new row and updating dgv rows (and validating them) and delete rows?
Can a dataview save these changes? and somehow apply them to the DB all toghether?
I've done these before by applying every change to the DB and refill the dgv after that. But I think it's not the right way. and I didn't find a full sample that can guide me through this.
next, to search in dgv and find the word that user wants, and somehow specify the found results (for example bolding the found words) in dgv. how it should be done? by dataview?
please help
|
|
|
|