Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

Saturday, March 31, 2012

Trimming spaces with calendar picker to send to sql statement

I have a Calendar PIcker that we choose a date from and send that out as a parameter to a sql statement. I have created my page in the visual studio designer and what I want to do is send is

RTrim(Calendar1.SelectedDate.ToShortDateString). My problem is since this was created in designer the code is all hidden. I can't place the RTrim() anywhere to accomplish this. Or maybe this whole process needs to be hard coded. It seems to me in VS 2003 you would see all the code thru expanding regions.

Thanks

Hey,

It should be there in the regions; I don't know how you are doing this; if you place it as an expression in the page, it could be in the page HTML. But how are you doing this? I need a little more info...

Tuesday, March 13, 2012

Troubles with INSERT INTO Statement...

hey all, im currently trying to do an insert statement, using textbox's and a variable. the only thing is its inserting txtTextBox.Text into the db instead of the value of that textbox...and i get this error when trying to insert my variable...

Exception Details: System.Data.SqlClient.SqlException: The name 'RndmNum' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Source Error:

Line 42: dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('txtName.Text', 'txtType.Text', 'txtLocation.Text', 'txtDesc.Text', RndmNum)"
Line 43: dbCommand = New SqlCommand(dbQuery,dbConnection)
Line 44: dbCommand.ExecuteNonQuery()
Line 45: dbConnection.Close
Line 46:

this is my insert statement:

dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('txtName.Text', 'txtType.Text', 'txtLocation.Text', 'txtDesc.Text', RndmNum)"

thanks everyone,
JustinYou are sending txtName.Text as a string. Your dbQuery needs to look like this:

dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('" & txtName.Text & "', '" & txtType.Text & "', '" & txtLocation.Text & "', '" & txtDesc.Text & "', " & RndmNum & ")"