DataSource Controls :: Benefits Of Using SqlCommand.ExecuteNonQuery Instead Of â€
Mar 29, 2010[Code]....
is used for update, insert and delete operations.Besides the fact
[Code]....
is used for update, insert and delete operations.Besides the fact
a) SqlCommand.ExecuteNonQuery is used for update, insert and delete operations.
Besides the fact that by using ExecuteNonQuery instead of ExecuteReader we automatically know there won't be any query results returned, are there some other benefits/reasons why ExecuteNonQuery should be used?
b) Similarly, if we want a database operation to return a single value, we should use ExecuteScalar instead of ExecuteNonquery ,where with the latter result would be returned via SqlParameter. Is there any particular reason why we should prefer ExecuteScalar over ExecuteNonQuery?
how to write code for database transaction(eg; Insert,delete,update) i want to write a better code
eg:sqlcommand.Commandtext="some sql insert query";
sqlcommand.parameter.Add(new sqlparameter("@cmdname","someValue"));
sqlcommand.ExecuteNonquery();
how to write the above code in better and safe way, i am expecting .net master also answer this question
put his view(pros and cons)
I would like to know what does a field timestamp in MSSQL do?I have read a book "ASP_NET_3_5_Social_Networking" and almost all the tabels have a columnt with type "timestamp" in their example app.What is the benefit of timestamp , and why should i use it?
View 5 RepliesI want to know about Change Data Capture(CDC) benefits in SQl Server?Especially on Data Base Volume?
View 1 RepliesIn my application at some places we have used ObjectDataSource and at other normal method calls to retrieve data.My question is then what exactly are the benefits of using ObjectDataSource ?In the example below "CODE ONE" makes a call to the Business Layer and then Binds the results to the Grid abd "CODE TWO" is using ObjectDataSource to do the same.Then how is ObjectDataSource better?
SuitableApplicant sa = new SuitableApplicant();
IList<HD.Recruitment.SuitableApplicant> list = new List<HD.Recruitment.SuitableApplicant>();
list = HS.Recruitment.RecruitmentService.GetSuitableAppls();
GridView1.DataSource = list;
[code]....
I have created a stored procedure that reset my tables' identity value. The store procedure works fine when I didrectly run it in my ms sql server 2008. It reset my table Identity value However, when I call it from my function reset, it returns -1, and does not reset my table identitity value. The function to restet my identity value is:
[Code]....
My stored procedure is
[Code]....
To call the the function:
Dim result
As
Integer = util.resetTableIdentity("myTable", "id", 60)
util.print(result)
I got result is -1, and it does ot reset my table identity. Why? How to resove it?
I want to add array list in sqlcommand.but i don't no how to pass it. My code is.
ArrayList
ProductId = new
ArrayList();
for (int i = 0; i < ShipmentPackage.Items.Count; i++)
{
ProductId.Add(ShipmentPackage.Items[i].ProductVariant.ProductID);
}
select * from TableName where id= ProductId(ProductId is my Arraylist)
i want to ask how to i set variable in asp:sqldatasource in sqlcommand in asp.net c#....
This is my code
asp.net
<dx:ASPxListBox ID="lsAssignToko" runat="server" DataSourceID="SqlDataSource6"
TextField="NAMA" ValueField="ID" AutoPostBack="true"
EnableCallbackMode="True" SelectionMode="CheckColumn"
OnSelectedIndexChanged="lsAssignToko_SelectedIndexChanged">
<Columns>
<dx:ListBoxColumn FieldName="ID"/>
<dx:ListBoxColumn FieldName="NAMA" />
</Columns>
</dx:ASPxListBox>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:Ora2010 %>"
ProviderName="<%$ ConnectionStrings:Ora2010.ProviderName %>"
SelectCommand="SELECT ID, NAMA FROM REF_TOKO WHERE ID IN ( :inTOKO ) ORDER BY NAMA">
<SelectParameters>
<asp:SessionParameter Name="inTOKO" SessionField="inTOKO" Size="200" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
c#
string dummy = "";
string data = "";
string inTK = "";
string inTOKO = "";
//string inTOKO1 = "";
int pot;
for (int i = lsToko.SelectedItems.Count - 1; i >= 0; i--)
{
string tok = lsToko.SelectedItem.Text.ToString();
data = lsToko.SelectedItem.Value.ToString();
dummy = dummy + "" + data + ",";
int index = lsToko.SelectedItem.Index;
lsToko.Items.RemoveAt(index);
}
if (lsToko.SelectedItems.Count <= 1)
{
inTK = dummy.Length.ToString();
pot = int.Parse(dummy.Length.ToString()) - 1;
inTOKO = dummy.Substring(0, pot);
}
Session["inTOKO"] = inTOKO;
the problem is where in my variable inTOKO consist of couple of value...
Example
while variable inTOKO = one value success but while value inTOKO = two value error
inTOKO = 1101111 => success
inTOKO = 1101111,1211321 => not success
i have the followng code:
[code]...
Now what I want is how can I print the complete sql statement and try to run it in sql query of
Sql server. How can I print Sql statement from sqlcommand. the cmd.commandtext seems notworking.
I have stepped through this code to test it and I am puzzled as to why the update isn't going through to the DB. When I run the SQL statement in SQL editor it updates fine. All variables are getting the proper values when I step through.
[Code]....
Im using above to makes sure that record is inserted to the SQL database before executing another function, but for some reason even if the record is NOT inserted other function has been called.(Other function is t update a Flag)
look at my code below and see where it goes wrong??
Part of the .Net Code
=============================================================
Private Sub GetAndInsert()[code]....
I have a feeling it could be that Rolling back is done in both .NET and SP??
can capture return value from a SQL by using SqlConnection SqlCommand
[Code]....
I'm looking for a way of being able to declare and execute a SqlCommand all on one line. At the moment I do something like:
Dim Cmd as New SqlCommand("....", Conn)
Cmd.ExecuteNonQuery
How can I do something like:
(New SqlCommand("....", Conn)).ExecuteNonQuery
I've a web form named contest, where users are to register for it. When the register is clicked on, details entered by the user will be saved into the database, but before it will check if the user has already participated in the contest (using AJAX). If the user has already participated, the button will be disabled. The problem is there is an error when I click on the register button.
The error:
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
Here's the codes I use:
[Code]....
I'm trying to determine whether it is better to declare the connection outside with it's own using statement or to create it inside the sqlcommand itself. This is in regards to a single command interaction with the database (no loops).
[Code]....
Or
[Code]....
How would I convert an empty textbox.text to null when updating/inserting using an SqlCommand? I've got this to populate the textbox:
If IsDBNull(dr("data")) Then
TextBox1.Text = ""
Else
TextBox1.Text = dr("data")
End If
Here's the SET of the SqlCommand:
[Code]....
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).
Possible Duplicate: In C#, should I use string.Empty or String.Empty or “” ? just don't understand the benefits of using String.Empty over "". Aside it being strongly typed its longer.
View 2 RepliesI think i understand the benefit of using themes but I want to be sure I understand correctly. I have previously used css to style my pages. I'm thinking about using themes in my next project. It provides a way to switch between the visual style of web controls and html elements. This could be done by allowing the user to choose a theme that is to their liking.
View 9 RepliesI am new to OOP. Kindly guide me why making business objects is good ? how and what benefit they bring in development. As I am new to OOP if please you decidable with example in simple way will be great help to me.
View 3 Replies1. .NET best practices, 2.best frameworks, and 3. benefits of the latest version?I need urgent help to convince the customer to use .NET, but they want me to list these 3 things. Can you help me list and/or point me to good summarized articles for these?
View 3 RepliesI am looking to build a web application for users to login and do various things on my website such as depositing money, withdrawal money, creating things that require money etc. I've heard MVC3 Linq and Entity Framework is a good way to build a asp.net c# web application, but I am confused because there are so many ways to build a web application,what is the most standard way to build a website, and what are the benefits of mvc3?
View 2 Repliesexplain me or provide me with a links of good articles/tutorials on "Benefits AndLimitations of Service Oriented Architecture" ?I mean Where to Use and Where not, the SOA.
View 11 Replieslet me know that what is the advantages / benefits of using multiple web.config files in web application
View 3 Replies