Adding The Where Statement In The SQL?
Apr 2, 2011
I managed to get the following Update SQL statement to work however I wish to add a WHERE.
So I have:
cmd = new SqlCommand("UPDATE Schedule SET Schd_Avaliable = '" + "No" + "'", con);
cmd.ExecuteNonQuery();
And I want to add a Where which looks for the Schd_ID in the table and a schdid which is from a session however with all the punctuation im unsure where to put it.
This is the Where I made:
WHERE Schd_ID = schdid
just unsure where to put that exactly in the line below without it throwing an error:
cmd = new SqlCommand("UPDATE Schedule SET Schd_Avaliable = '" + "No" + "'", con);
cmd.ExecuteNonQuery();
View 4 Replies
Similar Messages:
Aug 11, 2010
I have tested and tried to fix this until I am blue in the face and can not figure it out...
[Code]....
The SQL works fine if I just query in SQL - I only get the error when I try to get anything from the SalesPerson table and display it in my gridview.
View 7 Replies
Sep 25, 2010
have a very important issue,i have three Stored Procedures Sp1,Sp2 and Sp3 .the first one (Sp1) will execute the second one (Sp2) and save returned data into @tempTB1 and the Second one will execute the third one (Sp3) and save data into @tempTB2.if I execute the Sp2 it will works and it will returned me all my data from the Sp3 ,but the problem is in the Sp1, when i execute it it will display this Error:INSERT EXEC statement cannot be nested I tried to change the place of execute Sp2 and it display me another error:Cannot use the ROLLBACK statement within an INSERT-EXEC statement.
View 4 Replies
Mar 5, 2010
I am having trouble with this I have 3 Data tables i use over and over again which are cached I would like to write a LINQ statement which would do the following is this possible?
T-SQL VERSION:
SELECT P.[CID],P.[AID]
,B.[AID], B.[Data], B.[Status], B.[Language]
FROM MY_TABLE_1 P
JOIN
(
SELECT A.[AID], A.[Data], A.[Status], A.[Language] FROM MY_TABLE_2 A
UNION ALL
SELECT B.[AID], B.[Data], B.[Status], B.[Language] FROM MY_TABLE_3 B
) B on P.[AID] = B.[AID]
WHERE B.[Language] = 'EN' OR B.[Language] = 'ANY' AND B.STATUS = 1 AND B.[Language] = 'EN' OR B.[Language] = 'ANY' AND B.STATUS = 1
Then i would like it to create a result set of the following
Results:
|CID|AID|DATA|STATUS|LANGUAGE
View 3 Replies
Mar 1, 2011
I have two dropdown list, which is 'names' and 'types' and it's being populated by a dataset. It contains an additional item "-- ALL --" to indicate that all items of a particular field are being shown. I have an SQL select statement to filter the records according to the selected item of the dropdowns. I used a select statement to bind the records to a datagrid with regards to the selected items.
SELECT * FROM table where name = ddlnameselecteditem AND type = ddltypeselecteditem
The problem now is when I select a name from the names dropdownlist and types dropdownlist has a selection of -- ALL --, there would be no return records because there's no such thing as '-- ALL --' record in column 'types' i'm querying. I need to display rows of the selected 'name' while still showing all the 'types'. How could I achieve this? I think I need to avoid the '-- ALL --' item from the dropdownlist.
View 7 Replies
Apr 26, 2010
I'm pretty new at ASP. I've got a sheet I'm trying to modify using an IF statement. I tried putting them in, in different ways, but it either shows up in the form or I get the options multiple times
[Code]....
i have a variable picked up elsewhere strArea, so I was trying to do
something like
[Code]....
I have tried putting the if's in different places, as well as case statement
but usually I end up with my drop down option list as
1
1
2
1
2
3
View 3 Replies
Jan 26, 2011
i am having a listbox which contains some entities which i need to select in order to make the submit button work successfully but when no entity is selected it should give an error
protected void SubmitBtn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
on.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
[code]...
View 1 Replies
Oct 15, 2010
I would like to run an if statement but the condition uses a variable from the code behind. How do I call that variable? Side note... I am using a gridview and the variable is in a dataset (dsResult - idnbr colum)
<ItemTemplate>
<% string temp = (Eval("idnbr").ToString());
if (temp.Contains("X")) { %>
<asp:Label ID="Label1" runat="server" Text='<%# (Eval("old_amt").ToString(),"ccTot") %>'></asp:Label>
<% } else { %>
<asp:Label ID="Label2" runat="server" Text='<%# (Eval("new_amt").ToString(),"ccTot") %>'></asp:Label>
<% } %>
</ItemTemplate>
View 3 Replies
Feb 24, 2011
Why can't I set a variable within an If statement and use it outside? The following doesn't work - in the last line - variable unassigned???
[Code]....
View 2 Replies
Nov 5, 2010
I use LINQ.But I can not add data twice "ZnizanaDnevnica.
How could you do one box:
tbl_dnevnice_obracun tbl_dnevnice_obracun = new tbl_dnevnice_obracun()
{ZnizanaDnevnica = ((totDiffHours> = 6 & & totDiffHours <8)? Convert.ToDecimal (dt.Rows [0] ['Znizana']. ToString ()): 0),((totDiffHours> = 12
& & totDiffHours <24)? Convert.ToDecimal (dt.Rows [0] ['Znizana']. ToString ()
View 1 Replies
Jan 15, 2011
At University it was suggested to us that the best way to learn about designing and implementing databases is to practice the art. So I chose the following statement to implement and refine my skills:
Harpers Hauliers deliver shipments on contract for customers. Each contract is identified by a unique contract number. The contract may require a single or many shipments. Each shipment must be allocated resources of a vehicle (regisatration number, type, volume, weight), which is suitable for the shipment and a driver (name, address, telephone number) who is licensed to drive that type of vehicle.
As soon as a customer (companyname, address, telephone number) makes an enquiry, a pending contract is set up. The contract is then negotiated on price between the customer and the haulier. Not all pending contracts are successfully negotiated. Either the customer or the haulier may back out at this stage. If the haulier has previously carried for this customer and financial settlements were not made to his satisfaction, he may reject the contract. He may also reject the contract on the basis that he thinks the workload being undertaken is too big a risk for his company with this customer that is the contract is worth more than he is willing to risk for this customer.
An agreed contract requires the haulier to deliver the listed shipments between a start and an end date, at an agreed price. The haulier always takes out an insurance policy on the contract, in case he cannot allocate enough resources to the contract to get it delivered on time.For each shipment in the delivery there is an origin and destination. The shipment has a description, a weight and a volume. The haulier has a fleet of vehicles of different types and a staff of drivers with different license types, to match the vehicle types. During the contract, the haulier tries to allocate vehicle, driver and time-slot resources to each ship-ment. The vehicle must have a suitable volume and weight capacity and the driver must have a suitable license to drive that vehicle.
The time must be when the driver and vehicle are free and before the contract end date. As each shipment is delivered, it is marked off as delivered by the driver, giving the date and time of delivery. If not all shipments are delivered by the contract end date, the con-tract becomes overdue, incurring a penalty cost on the haulier. When all shipments are delivered, the haulier invoices the customer for the required amount. Each invoice is has a date and is identified by a unique invoice number . Payment from the customer may be in full or may be partial. The contract is kept active until all payments have been made against it.
And here is the ERD that I have come up with. I have created the ERD in Visio 2010.
[IMG]http://i56.tinypic.com/6s43t4.jpg[/IMG]
Can someone who's an expert in Database design kindly check my ERD and see if it perfectly matches the Problem Statement.
View 16 Replies
May 24, 2010
If statement is not working
View 3 Replies
Jan 7, 2011
I want to return values where Worldwide = yes or where visible = yes and in State = Florida but this is not returning all the other values where the Worldwide is yes
select * from Table1
where (visible = 'yes' and State = 'Florida') or Worldwide= 'yes'
order by ID DESC
Edit: My BAD
Shit sorry guys/girls, this statement does work! I had Select TOP 8 * in my statement that is why it did not return all the records! When I took the TOP 8 out it worked!
View 4 Replies
May 20, 2010
My switch is based on a string, the text value of an server control. code:
[Code]....
[Code]....
View 3 Replies
Sep 9, 2010
I am trying to format money to be inserted to an sql statement. I currently have this
str = str + "'" + a.Trim + "', '" + b.Trim + "', '" + System.DateTime.Now + "', money, "
when i hard code money as 2.00, for example:
str = str + "'" + a.Trim + "', '" + b.Trim + "', '" + System.DateTime.Now + "', 2.00, "
it works fine, but when i am using a variable like dim money as double
money = dr("amount").ToString()
as with the 1st example i get the error message:
Input string was not in a correct format.
View 8 Replies
Mar 22, 2011
Why wont this work? Bin trying everything.
Code:
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/DataBase_J_Wall.mdb"));
con.Open();
OleDbCommand cmd = new OleDbCommand("UPDATE MAIN_TBL SET Person_Name='" + txtboxname.Text + "', Person_Address='" + txtboxaddress.Text + "' where Person_Password='" + Session["userbruger"] + "'", con);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
Response.Redirect("Change_My_Info.aspx");
And yes, the session is there.
View 5 Replies
Nov 15, 2010
How do I continue a VB statement on the next line, to improve readability?
View 4 Replies
Mar 25, 2011
I want to create a program that allows me to enter the name of a table, a field along with a value. The program should concatenate the values to form a valid SQL select statement. I can also modify the program to include multiple field names and values. Example: -Select “FieldName” from “TableName” where “FieldName”= “Value” I have created 3 textboxes called and 3 labels named Select, From and Where This is my code here, i would need an assistance on the right way to achieve this, maybe mine is wrong.
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SelectItem As String
Dim From As String
Dim Where As String
SelectItem = txtSelectItem.Text
From = txtFrom.Text
Where = txtWhere.Text
lblDisplay = "Select" & " " & SelectItem & " " & "From" & " " & From & " " & Where
End Sub
End Class
View 3 Replies
Jul 4, 2010
Using the this article - [URL], where do I place my redirection statement?
Say for example, after a successful insertion of a new record I am going to redirect the page to success.aspx saying "A new record has been successfully added".
Where am I going to place my redirection statement?
Is it in this way
Code:
[code]....
View 7 Replies
Feb 16, 2011
I am fairly new to Visual Web Developer and am trying something out. I have an ASPX page done with a button (using VB). I have already been able to get the username variable to write to the page using Response.write(Environment.UserName). I want to go a little farther with this and extract the field [Program] from a table tblUserInfo in the sql database where the Env.UserName = tblUserInfo.username.
Now I have started to code the button but can't figure out how to use an SQL statement to extract that data...
[Code]....
My end result will be once I can see what program a user is linked to in the table, the question form they are going to will be different based on that program value... but one step at a time eh.
View 3 Replies
Mar 16, 2011
Response.Write(" alert('General Settings Updated Successfully');"); statement changes the layout of my webpage i want to keep the layout as it is..
View 1 Replies
Oct 22, 2010
I have a textbox named text1. I use an INSERT INTO sql statement on enter text1's data into my database. But there is a problem. Whenever I use ' in my textbox, I get an error for INSERT INTO statement uses the same ' to enclose string data. The code is like this:
objcmd.InsertCommand = New OleDbCommand
View 2 Replies
Mar 9, 2011
I'm converting a string to integer and than inserting this integer in my post table.
int currTopicID = Convert.ToInt32(id.Text);
SqlCommand cmd = new SqlCommand("INSERT INTO post VALUES(currTopicID)", con);
The problem is that currTopicID isn't being recognized as an integer when i do the insertion.
View 4 Replies
Nov 1, 2010
I'm having problems with creating detele functionality to my asp.net page. I have found lots of bits of code indicating parts of how to do it, but not in its entirety. Could someone display it in a more complete version so I could have something to compare and figure out what i am doing wrong?
View 3 Replies
Jun 10, 2010
I've got a form view that gets it's data from an access database:
I need to make the text of a label display Correct if the contents of the database field is 1 and Incorrect if it is 0
I was hoping I could turn the label's value to a string
(like this: <asp:Label ID="RightWrongLabel" runat="server" Text='<%# Eval("RightWrong").ToString() %>'/>)
and then access it in code view and write an if statement, but when I try to access the string in codebehind it says it's not available in the current context.
View 4 Replies