Showing posts with label retieve. Show all posts
Showing posts with label retieve. Show all posts

Monday, March 12, 2012

Pls Help... How can I retieve the value of fields in my sqldatabase using sqldatareader

Please help me with my thesis... I am using ASP.NET

How can I retieve the value of fields in my sqldatabase using sqldatareader

thnks

Try the training videos in the SQL section.....http://www.asp.net/learn/sql-videos/

These will help you get started learning how to retreive data from the database

Burl

|||Dim DBConnAsNew SqlConnection("Server=localhost;Password=YourPWD;Persist Security Info=False;User ID=YourID;Initial Catalog=Northwind;Data Source=YourDataSource")Dim DBCmdAsNew SqlCommandDim DRAs SqlDataReaderDBCmd =New SqlCommand("SELECT Id, Name FROM Customers WHERE CustomerID = @.CustomerID", DBConn)DBCmd.Parameters.Add("@.CustomerID", SqlDbType.NChar, 5).Value = txtQuery.TextDR = DBCmd.ExecuteReader()

While(DR.Read())
{
id as string = DR["ID"].ToString()
}

|||

Hey it is good to read the DataTable values from Data Reader. Try using the linkhttp://dotnetsavvyblog.blogspot.com/2007/11/to-retrieve-fields-using-sqlreader.html.

Do let me know if you still face problems.

Saturday, February 25, 2012

Please Help: Error: Missing semicolon (;) at end of SQL statement.

Hey

I am trying to retieve a value from teh database and add one to it, then update the database with thenew value before redirecting to a page.

I am recieving this error and don't know why, i have the following coed below.


Dim objReaderQ as OleDBDataReader

Dim strSQLRead As String
Dim objCmd As New OleDbCommand

strSQLRead ="Select Quantity from tblCart Where (Productid=" & intProdidHold & ") AND (Cartid='" & strCartid & "')"

objCmd = new OleDbCommand(strSQLRead, objConn)
objReaderQ = objCmd.ExecuteReader()

if objReaderQ.Read()
'update quantity by 1

Dim i as integer
i = objReaderQ("quantity")
i = i + 1

objReaderQ.Close()

Dim strSQLQuantity as String = "INSERT INTO tblCart (Quantity) VALUES (@.quantity) WHERE (productid=" & intProdidHold & ") AND (Cartid='" & strCartid & "');"

Dim objCmdQuantity As New OleDbCommand(strSQLQuantity, objConn)

objCmdQuantity.Connection = objConn

objCmdQuantity.Parameters.Add("@.quantity", OleDbType.VarChar, 255)
objCmdQuantity.Parameters("@.quantity").Value = i

objCmdQuantity.ExecuteNonQuery() ' <-- Error Is Occuring On This Line

Response.Redirect("ViewBasket.aspx")

end if

I really can't see what is wrong as i have placed the semi colon it wanted at the end of the string.

Thanks you for your time

ChrisHey,

I have solved this problem, wrong sql statement, should be update! lol :(

But i do have the problem that once go to the viewbasket.aspx page it shows the product with the quantity 1, as it pulls the quantity from the db and its default value is 1 (which is correct).

But now if that same product is clicked 'Add To basket' for a second time, it executes the above code and goes to the viewbasket.aspx page, but the quantity stays as 1 ! (should be 2)

And now if that same product is clicked 'Add To basket' for a third time, it executes the above code again and goes to the viewbasket.aspx page, but this time the quantity is 2 ! (should be 3)

From this point on the code worked fine and increments the number properly, 4,5,6 etc..

Any idea why the first two clicks dont work ?

Thank you for your help

Chris