|
Sorry, never called it stepping thru, just debugging it....self taught(if you want to call it that) and so far (knock on wood) this is the first real problem I've run into, that I couldn't fix by either re-writing or re-evaluating what I've written. sorry to be of a frustration.
I did step-thru or debug it and found that on the 'object o = dataReader.GetString(0);' you had me test, I am getting the following: o <undefined value=""> System.Object
and for the 'string Amount = dataReader.GetString(0);' I am returning a null, but unless i'm not pulling the correct field the data shouldn't be a null, rather a value of 331.000. Unless its not pulling the data from the variables i set with the +location_id+ which if that were the case, it seems that I would have a failure elsewhere....in the query, but it IS pushing the console.writeline values to the query, so.......
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
Can you select the parameter by name instead of index ? That is dataReader.GetString("Amount") ?
Doesn't look like it. What if you replace this:
"SELECT sum (Amount) From Transaction_table WHERE Location_ID = @machineName and Shift_Number = @ShiftNumber"
with this:
string.Format("SELECT sum(Amount) as TotalAmount from Transaction_table where Location_ID = {0} and Shift_Number = {1}", machine_name, shift_number)
so that you don't have to mess with parameters at all, just pass in the SQL. ( and so your result has a name )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian,
We had it all backwards.....
I was using the Getint32 class and while that is fine I am only trying to retrieve one result and since I was creating it as a 'virtual' column it wouldn't pull becasue I apparently was trying to read it in the .net framework data type, but it was returning .net data provider data type. SO this basically means that no matter how i queried it it was never going to convert to the correct data type unless i told it to. plus, when we tried to change the ordnal type from numeric (0,1,2,etc) to alpha ("Amount") it would not read since it only reads ordnals as numeric values. intersting huh? and if it ever helps you out, the datareader provides the fastest level of data retrieval from a DBMS if all you are doing is querying it for reading purposes, so if at work you guys never have to update or insert it may be helpfull to use it.....
who knows, maybe this will all help you or someone else out there one day.....
THANKS FOR YOUR HELP
talk to you later.....but hopefully not!
have a nice day!
Oh, by the way here's the code that paid the bills! ::::
Console.WriteLine("Current Shift Value on machine [" + Location_ID + "] is $" + dataReader["Value"].ToString());
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
Hi Folks,
I'm trying to access a CSV file as an ODBC to import some data into an Oracle Database. I almost have it.
I have the connect string for Microsoft Text Driver. I have sorted out how to access the CSV file as a table. What I can't figure out how to do is get the Microsoft Text Driver to stop recognizing every field as a VARCHAR(255). This takes a horrible amoung of space and causes compatibility problems with the Oracle table I'm using.
The Microsoft Text Driver will recognize a header on a CSV file with the field names, but I can't figure out how to specify data types with the correct syntax.
Help!!!!!
Matthew Evans
Canada
|
|
|
|
|
With ado (not .net) if i have a RecordSet (basicly an in memory table) can i connect to it as if it where a database and run a select statment against it to return a new recordset? And if it posible would you be so kind as to include a code sniplet.
|
|
|
|
|
I have an application using SQL Server database. After a few insert new data from application into database. That database is seem to be stucked. I can query any function from it any more. I must wait for a while, stop and then restart SQL Server, close (if it's opening) and then open Query Analyzer and change the database processing to the database that my application works with in order to make it works again . And i must exactly follow all the steps above to make it works again.
If i try inserting data from Query Analyzer, there's no thing wrong appears. but right after that if i try to delete that database, i will receive a message that i can't delete that database because it's in use (although i closed my app and query analyzer already). I (again) must stop, and restart SQL Server to delete.
What's my problem? The error is caused by my app or my SQL Server?
Please help me. Thanks!
|
|
|
|
|
I'd check for open transactions..that aren't being committed/rolled back etc..
|
|
|
|
|
I am trying to connect to a database on an AS400 via ODBC and getting some issues with the connection string. I have searched and not found anything that will help.
My connection string is
Private Const RSEL_CONNECTION = "Driver={Client Access ODBC Driver (32- bit)};System=XXX; DBQ=LTL400TNT3;Uid=XXX;Pwd=XXX;"
My calling code is
Dim conn As OdbcConnection
conn = New OdbcConnection(RSEL_Connection)
My error
Message "Format of the initialization string does not conform to specification starting at index 0." String
Any help would be much appreciated. Also, i need to do this via ODBC or OLEDB. I know this is slower, but I cannot use the beta managed database connectors available.
Thanks,
Scott
|
|
|
|
|
Hai,
I want to get the last 10 records from a table containing 100 records.What will be the siplest SQL query ,I can use for retreiving last 10 records,without giving any conditions.I am sure somebody can show my way.
Thank you,
Rahul.
|
|
|
|
|
This is the best I can come up with:
SELECT TOP 10 FROM MyTable ORDER BY ClusteredIndexColumns DESC
Remember that the SELECT statement returns a set, and in a set there is no concept of order, so, in order to maintain this artificial order, to get the first 10 rows chance the DESC to ASC
The ClusteredIndexColumns are the columns that make up your clustered index, this is often the primary key.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Hai Colin,
Great.That seems to be the best and simplest way.Thank you very much for your valuable information and for the fantastic help.
Thank you,
Rahul
|
|
|
|
|
I want to know who i can access specif rows in dataset to generate values in other rows: for example, if i ve in forst row [A1 , A2 , A3] and in the second row i ve to calculate value like this [ A5, A4-A2 , A5-(A4-A2)]
remark that A2 from pervious row , i means i need to know how to loop on dataset records in reporting services
need solution as soon as possible
|
|
|
|
|
Hi
Does anyone know how you check to see if a table in a database allready exists?
Hehe. Maybe I should give some more information here:
I have a direct connection to a Access Database via a OleDB Connection, and I am programming in C#.
Wilye
|
|
|
|
|
|
i also use this one, but never tested on MS SQL Server (i use Oracle DB) :
select table_name
from user_tables
order by table_name asc;
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
DataTable schemaTable = MyoledbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables_Info,
new object[] {null, null, null, "TABLE"});
//The schema table's third column contains the Table Names.
//Explore this Table and the commands.
Cheers,
Akos
|
|
|
|
|
YES. That worked. Thanks
Wilye
|
|
|
|
|
Hi. I have a webform that has several dropboxes that are dynamically populated from a ms access database. Im fairly new to database design. In my drop boxes i have add a "All" Item. which will allow me to search the database for all records.
my problem is:
Drop box one is listing several industries. (independant)
Drop box two lists several uses ( which dynamically change based on the industry selected)
Drop box 3 lists categories (independant)
drop box 4 lists options based on the selected category
I want to be able to search my table for records that match all of the user selected criteria.
im trying to use parameters and I cant figure out the best way to do this... I know what ive done probably isn't the best way to do this... but this is an example of how im creating my query string.
Sub CreateQuery()
Dim SelectPhotos As OleDbCommand
Dim Photo As OleDbDataReader
Dim strSelect As String
Dim SelectedIndustry As String
Dim SelectedUse As String
Dim SelectedCategory As String
Dim SelectedOption As String
strSelect = "Select * From Catalog1 Where "
SelectedIndustry = dropIndustry.SelectedItem.Value
SelectedUse = dropUse.SelectedItem.Value
SelectedCategory = dropCategory.SelectedItem.Value
SelectedOption = dropOption.SelectedItem.Value
SelectPhotos = New OleDbCommand(strSelect, conPhoto)
If SelectedIndustry > 0 Then
SelectPhotos.Parameters.Add("@selectedIndustry", SelectedIndustry)
strSelect += "IndustryID=@SelectedIndustry And "
End If
If SelectedUse > 0 Then
SelectPhotos.Parameters.Add("@selectedUse", SelectedUse)
strSelect += "UseID=@SelectedUse And "
End If
If SelectedCategory > 0 Then
SelectPhotos.Parameters.Add("@selectedCategory ", SelectedCategory)
strSelect += "CategoryID=@SelectedCategory And "
End If
If SelectedOption > 0 Then
SelectPhotos.Parameters.Add("@selectedOption ", SelectedOption)
strSelect += "OptionID=@SelectedOption"
End If
conPhoto.Open()
Photo = SelectPhotos.ExecuteReader()
Photo.Close()
conPhoto.Close()
lblTest.Text = strSelect
End Sub
|
|
|
|
|
Hi
i have a oledbcommand with parameter:
"insert into T(a,b) values (@a,@b);"+"select @@IDENTITY as '" + "a" + "'";
.
.
.
add CommandParameters
.
.
.
then
.
.
.
int retValue = oleDbCommand.ExecuteScalar();
.
.
.
but i get error :
Characters found after end of SQL statement
What should i do
|
|
|
|
|
WDI wrote:
"insert into T(a,b) values (@a,@b);"+"select @@IDENTITY as '" + "a" + "'";
This is nuts. Why are you concatenating string literals like this? You could do all this in one literal string:
insert into T(a,b) values (@a,@b);select @@IDENTITY as 'a' And as you can see this is much easier to read. I suspect there is something more going on here because you are unlikely to have a table named T with columns name a and b. So, we cannot see what your proper string is, which is the cause of your problem, because you have chosen to obfuscate it. This does not help us help you. If you need to obfuscate parts of the code then do that to code that is incidental to the problem, not directly related to it.
Next, what is this as 'a' on the end. I'm guessing this will confuse the query parser because the apostrophe is for string literals in SQL, not for naming columns. Use [a] or "a" - better yet, because you are using ExecuteScalar, don't name the column at all.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
hello dear,
I want to register the server from my local enteprize manager .bu this error apeared :
the server doesn't exist or access is denied
I called the manager of the server he said the server have 20 sites that working properly with out problem.and you should setting the control pannel of your local computer.what setting?how?
thanks in advanced.
|
|
|
|
|
If you have any adea please tell me?
thanks in advanced.
|
|
|
|
|
I want to take all the data from a column of a table. Foreach value i get, I used it as a field to my insert function into another table . I some kind like
for(int i=0;i
|
|
|
|
|
Yes, you could do it very easily like this:
string sql = "INSERT INTO Table2 VALUES (@value1, .....)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@value1", SqlDbType.Int);
foreach(DataRow row in table1.Rows)
{
cmd.Parameters[0].Value = row[1];
cmd.ExecuteNonQuery();
} It can be done with a stored procedure in the same way, only if you change the sql variable to the name of a stored procedure that takes one parameter named value1 .
I hope it helps.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I means that we'll do all that things in a single store procedure, not in C# (include the way we take each row from a table). And then, in C#, we just call that store procedure to execute automatic. Can you help me?
Thanks your reply.
|
|
|
|