SQL Server :: Run Multiple MS Update Queries
Sep 11, 2010On satisfying the If condition, I need to run 2 MS SQL update queries. How can I accomplish this? I am using C# as the server side language.
View 6 RepliesOn satisfying the If condition, I need to run 2 MS SQL update queries. How can I accomplish this? I am using C# as the server side language.
View 6 RepliesI want to find the sum of each tables fileld. how can do this. i tried the following.but could nt get the correct sum. "SELECT SUM(gb) FROM data20 union all SELECT SUM(gb) FROM data10 union all SELECT SUM(gb) FROM data5 union all SELECT SUM(gb) FROM data6"
View 7 Replieshow to run multiple queries on a single button click. Actually I want whatever a user write in text box and click the button the text would get inserted in table category and also a table name project should get updated. I am using Sql server 2005 and c#
View 2 RepliesI am trying to do multiple queries with multiple CheckBoxes. This code worked until just recently, and I didn't make any changes other than adding a single field to my SQL Server DB; field is named 'Crawl'. Now, nothing works! SearchCheckBox.aspx:
[Code]....
SearchCheckBox.aspx.vb
[Code]....
In DesignView, the error reads 'Error Creating control SqlDataSource3' Literal
content ('connectionString="Data Source=EXCEL-4J2W8KYNPSQLEXPRESS;Initial
Catalog=PubCrawls;Integrated Security=True" ProviderName="System.Data.SqlClient"
SelectCommand="SELECT ID,
Pub, Street, Neighborhood, City, State, RelativeAddress, Crawl FROM ListofPubs
WHERE (Neighborhood = @Neighborhood1) OR (Neighborhood = @Neighborhood2) OR
(Neighborhood = @Neighborhood3) _
OR (Neighborhood =
@Neighborhood4) OR (Neighborhood = @Neighborhood5) OR (Neighborhood =
@Neighborhood6) OR (Neighborhood = @Neighborhood7) OR (Neighborhood =
@Neighborhood8) OR (Neighborhood = @Neighborhood9) . . .
goes on like this for a while) is not allowed within a 'System.Web.UI.WebControls.SqlDataSource' This line is highlighted red: connectionString="Data Source=EXCEL-4J2W8KYNPSQLEXPRESS;Initial Catalog=PubCrawls;Integrated Security=True" Finally, there are 19 'Neighborhoods' in my list. There must be a way to loop through the neighborhoods in my SQL statement, right. For Loop or While Loop?
protected void Button2_Click(object sender, EventArgs e)
{
String a = DropDownList1.SelectedItem.Value;
String b = DropDownList3.SelectedItem.Value.PadLeft(3, '0');
String c = TextBox2.Text.PadLeft(5,'0').ToString();
String d = TextBox3.Text.ToString();
String digit = a+ b + c + d;
try
{
myConn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=testcase;User=root;Password=root;Option=3;");
myConn.Open();
//**
string sql = "select * from testcase.main where reg_no =?";
//**
OdbcCommand cmd = new OdbcCommand(sql, myConn);
//**
cmd.Parameters.AddWithValue("?", digit);
MyReader = cmd.ExecuteReader();
//**
while (MyReader.Read())
{
String f = MyReader["pet_name"].ToString();
String g = MyReader["res_name"].ToString();
Label9.Visible = true;
Label9.Text = f;
Label10.Visible = true;
Label10.Text = "VS";
//Label11.Visible = true;
Label11.Text = g;
}
MyReader.Close();
}
catch (Exception e1)
{
Response.Write(e1.ToString());
}
finally
{
if (MyReader != null && !MyReader.IsClosed)
{
MyReader.Close();
}
if (myConn != null && myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}
I want to add another sql query which is using two tables to fetch the data and than i want to display it in a dropdownlist after fetching data from database. How should i proceed?? Should i create a totally new connection? I tried many different ways like, creating new connection and new reader and entire try and catch block i coded again but on running the website i t was taking very long to load the contents. What i did i modified only this portion(below code) and used the entire try catch again but it dint work.
while (MyReader1.Read())
{
String f = MyReader1["ret"].ToString();
DropDownList1.Items.Add(f);
}
I am creating entries in a contract table using linq to sql.
One column needs to conditionally be assigned an application number from a range of values.
I'd like to simply increment the max existing value, however it is a multi-user application and I'm concerned about multiple contracts receiving the same app number if they happen too close together.
Is there a way to either force the entire thing to use the same transaction, or to execute both during the same submit?
We are building a front page/dashboard that queries our database for live statistics. The page has 3 update panels, each update panel has a user control that pulls data for it's box. Lets call the user controls UC_NotStarted, UC_Active and UC_Finished.
We have built the queries that return the data and all of them take a while to run (~7 seconds each). So if we let the first page run with one update panel the image spins for ~21 seconds and display everything. We have broken that code into 3 update panels and set the loading to conditional. When we do this we get one box to load every 7 seconds. That's a step in the right direction but they load sequentially (UC_NotStarted is queried waits 7 seconds and displays, then UC_Active goes for 7 seconds, and finally UC_Finished runs for 7 seconds). We are still at 21 seconds but data is being shown every 7 seconds.
We would like all of the data to be shown in 7 seconds since all of the update panels should be fetching the data at the same time. Instead of using LinqToSQL to pull the data I am now leaning towards web services to get it but not sure if that will work.
I have a drop down with several option. I would like that if a certain item is select then a certain query will run. I read a post that
azamsharp on 12/23/03 .In that post he suggested to do:
string myProcedure = DropDownList.SelectedItem.value.ToString();
SqlCommand myCommand = new SqlCommand("myProcedure",myConnection);
while reading through the post it seems that this wasn't a great idea.
The goal is to update multiple row in the table. In my table there is 3 col, at here i will name it col1, col2 and col 3. The number of row in the table is, let say 10. Each row will have a different value in col1 and col2, where col3 value is static.
Something like the below;
|col1 |col2 |col3
Row1 |a |b |c
Row2 |aa |bb |c
Row3 |aaa |bb |c
My update statement;
UPDATE table1 SET Col2 = CASE Col1
WHEN 'a' THEN '1'
WHEN'aa' THEN '2'
End where col3 IN (c)
In plain, i just wanna update col2, but had to base on col1 and col3 value. After I run the statement above, it will empty Row3's col2, but in fact, i don't want to update Row3's col2.
Is it possible to write multiple queries on a single button click? if yes then how?
View 5 Repliesi want to display results from multiple queries in a repeater... is it possible? for example, a user searches for a keyword "test" i search 4 different databases for it, and display results from all 4 in one repeater.
View 2 Repliesin VB, exactly how would you show only 1 gridview for this type of page example, where a user can fill in multiple options for searching:
Enter first and last name
_______firstname
_______lastname
[code]...
Here is my situation: I use the SqlCommond to update some records in the SQL Server in a ASP.NET web site. Users can choose which records they want to update. Sometimes they may choose 40 or 60 records to update at a time.Is there any good way to do it? I do not want to do like it
foreach(string ID in List)
{
Update here
}
I am working on asp.net 3.5 and in MVC using Linq to SQL classes. In my MVC project i am calling stored procedure using linq to sql that conatin query joining two tables.Below is my code in Partial class
[
Function(Name="dbo.GetUserWiseThreadDetail_SP")]
[ResultType(typeof(Thread))]
[ResultType(typeof(Reply))]
public
IMultipleResults GetUserWiseThreadDetail_SP([Parameter(DbType="VarChar(30)")]
string userID)
{
ExecuteResult result = this.ExecuteMethodCall(this,
(MethodInfo)(MethodInfo.GetCurrentMethod())), userID);
return ((IMultipleResults)(result.ReturnValue));
}
In one of the controller i have made one more class
public class
MypostIndexData
{
public
IEnumerable<Thread> Thrds {
get;
set; }
public
IEnumerable<Reply> Repls {
get;
set; }
public MypostIndexData(IEnumerable<Thread>
thrds,IEnumerable<Reply> repls)
{
this.Thrds=thrds;this.Repls=repls;
}
}
finally coding of controller action method
ForumDataContext pmforum = new
PMForumDataContext();
public
ActionResult MyPosts(string userId)
{
IEnumerable<Thread>thrds;
IEnumerable<Reply>repls;
IMultipleResults result = pmforum.GetUserWiseThreadDetail_SP(userId); (this satement doesnot give any result,if i execute stored proc in
sql it give the results)
thrds = result.GetResult<Thread>();
List<Thread> thrdlist =
new
List<Thread>(thrds);
repls = result.GetResult<Reply>();
List<Reply> replylist;
if (repls !=
null)
{
replylist = new
List<Reply>(repls);
}
return View(new
MypostIndexData(thrds,repls));
I am unable to understand why i am not getting any results?
I have two tables, Customer and CustomerPhone.
Single record in Customer can have multiple CustomerPhone records. As you see in the image below, Phone and Fax resides in CustomerPhone table whereas the rest of the fields resides in Customer table. If user want to edits a customer record, obviously i will have to update the record in Customer table and at least two records from CustomerPhone (Phone and Fax).
I could write two update statements, one Update customerPhone and the second update Customer table. Is there a better solution?
I have a gridview that pulls data from two tables, CLIENT and PAYMENT. I want to add the edit, delete functions to the gridview for the payment portion of the table, that is to edit or delete the payments but not the client. I've manually enabled the edit, delete functions and input the queries. I've also deleted the textboxes from the templates which draw from the CLIENT table so they cannot be edited. Everything looks good on the surface until I actually go to edit or delete anything, and it has no effect.Here's the structure of the two tables:
CLIENT PAYMENT
ClientID Pk PaymentNumber Pk
FName CLIENT$ClientID Fk
LName PaymentDate
ContactNo NULL PaymentAmount
ArrivalDate PaymentDetails NULL
DepartureDate NULL
CurrentResident
Here's the update query:
UPDATE [PAYMENT] SET [PaymentDate] = @PaymentDate, [PaymentAmount] = @PaymentAmount, [PaymentDetails] = @PaymentDetails WHERE [PaymentNumber] = @original_PaymentNumber AND [CLIENT$ClientID] = @original_CLIENT$ClientID AND [PaymentDate] = @original_PaymentDate
AND [PaymentAmount] = @original_PaymentAmount AND (([PaymentDetails] = @original_PaymentDetails) OR ([PaymentDetails] IS NULL AND @original_PaymentDetails IS NULL))
Finally, here's the delete query:
DELETE FROM [PAYMENT] WHERE [PaymentNumber] = @original_PaymentNumber AND [CLIENT$ClientID] = @original_CLIENT$ClientID AND [PaymentDate] = @original_PaymentDate AND [PaymentAmount] = @original_PaymentAmount AND (([PaymentDetails] = @original_PaymentDetails)
OR ([PaymentDetails] IS NULL AND @original_PaymentDetails IS NULL))
I am accepting query/queries from user (our support team) in a text box where user can enter only one query or multiple queries. I need to display result of all queries entered in the textbox. If it is SELECT statement then result of that statement in grid which is done. If UPDATE/INSERT/DELETE then total number of rows affected which is also done but if only one UPDATE/INSERT/DELETE statement is entered in the textbox.
If user enters 2 UPDATE statements and then a SELECT statement then how can I get number of rows affected for individual UPDATE statements just like SQL Server Qury Analyzer displays messages in its result pane.
e.g.
(6 row(s) affected) -- first UPDATE statement
(4 row(s) affected) -- second UPDATE statement
(16 row(s) affected) -- for SELECT statement (grid will also be displayed along with these messages).
I tried almost everything, SqlDataSource (returns count of first statement only), SqlCommand.ExecuteNonQuery and DataAdapter.Fill (returns count of last statement only).
I have several rows in my database like this
ID Status Type Count Event
291 0 0 2 1
523 1 2 0 4
and so on. When my user performs some basic actions on my website, some values are passed through JSON to the server and are then converted into custom objects with 5 int properties(so they match the table). These objects that the server receives are the rows to be updated(based on ID) and the values for each column. How can I do this in one SQL statement without the need to loop through each object and update them all seperately? Is there a way? Preferably compatible with SQLServer 2005.
I have a table line (ID, LineNo, LineName) having values as :
1, 1, <blank>
2, 2, <blank>
3, 3, <blank>
ID is PK with Auto-Increment and LinNo(I am manually incrementing through ASP.Net Page while record insertion) Now i have to write a query such that it updates LineName column from line table which is blank(as shown above) with values from table linet(linenamet) having values as :
a
b
c
My trial query is :
update line set LineName = (select linenamet from linet);
It gives ERROR as : Subquery returns more than 1 row
Expected Result : After Updation it should show line table as :
1, 1, a
2, 2, b
3, 3, c
I have to subqueries and i need them to be sidebyside but when i "union all" one goes under.
What is the way i can have them appear beside each other?
I have a sql query that returns 4 columns CustName CustId CustZip CustPhone
I have a second sql query that returns the following 5 columns
CustName CustId CustZip CustEmail CustAddress
Both queries, query different data tables in the database, but return columns that are common to
both.
How do I union the two queries(Assuming a union is needed)
Which will result in no duplicates and an end result being the following output:
CustName CustId CustZip CustPhone CustEmail CustAddress
As you can see we want to not have duplicate values on output. So something like the following
is not acceptable:
Jeff Stamper 2222234 81224 498-300-2222
Jeff Stamper 2222234 81224 498-300-2222 js@jj.com 122 Mars Blvd
Karen Bops 3322234 81666 498-300-2222
Karen Bops 3322234 81666 498-300-2222 kb@lpo.com 322 Jamer Road
I want to combine two queries like :
select name as name1 from table1 where id = 6
and
select name as name2 from table1 where id = 2.
I need a single resultset. How can I do that?
How to debug queries and stored procedures in sql server 2008 like we doing in vs
View 1 RepliesI have a menu table which has a (mostly) unlimited number of levels/tiers:
[Code]....
I also have a working function which will give the up and down tiers based on a given MainMenuId:
[Code]....
My question is, is there a better way to do this such as combining the two querries? Every attempt I have made results in a "The Statement terminated. The maximum recursion 100 has been exhausted before statement completion"
In my stored procedure there are 8 queries for 8 tables.Each query has joins and sub queries. I am passing parameters & stored procedure name from front end(designed in asp.net 3.5) can we execute that 8 queries at the same time i.e. parallel execution so that I can minimize stored procedure execution time?
View 6 Replies