DataSource Controls :: SqlCommand With The SqlConnection Declared Inside Or Out?

Mar 25, 2010

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]....

View 6 Replies


Similar Messages:

DataSource Controls :: Can Capture Return Value From A SQL By Using SqlConnection SqlCommand

Apr 15, 2010

can capture return value from a SQL by using SqlConnection SqlCommand

[Code]....

View 3 Replies

Web Forms :: Declaring The SqlConnection And SqlCommand Objects Without CodeBehind?

Sep 11, 2010

Declaring the SqlConnection and SqlCommand objects in a webform without CodeBehind I am trying to query data from a MS SQL server with a C# web form without "CodeBehind". I want to write the information to a table in the web form's body.

I am having trouble declaring the SqlConnection and SqlCommand objects that connect to the server.

How do you use "using System;", "using System.Data;", "using System.Data.SqlClient" inside the script element of an .ASPX file?

(code below)

[Code]....

View 5 Replies

DataSource Controls :: Common Sqlconnection?

Mar 4, 2010

i have 5 methods in classA. each and every methods i have open the sqlconnection and close it, instead of that is there anyway to create a sqlconnection at one time if its opened then no need to create a new connection, if its closed then we have to connect.

View 5 Replies

DataSource Controls :: Use ConnectionString In New SQLConnection?

May 22, 2010

Is it possible to use a pre-existing ConnectionString in this construction?

myConnection = New SqlConnection("server=localhost;" & "database=pubs;Trusted_Connection=Yes")

Regards -Penn

View 3 Replies

DataSource Controls :: Singleton Pattern For SQLConnection?

Apr 19, 2010

I have a whole bunch of data access methods where in each one I am doing this

[Code]....

and them moving on with my SqlCommand and SqlDataReader and so on.Is this creating to many instances of an SQLConnection?I was thinking doing this instead. Creating a SqlConnection Manager which would look like this

[Code]....

and then in my database access methods

[Code]....

Is this a good or bad idea and why?Also would this even be neccesary?

View 2 Replies

DataSource Controls :: Can't Update The Information Using SqlConnection

Jul 2, 2010

i am making a simple cms system

but I have a problem when updating some information

here is the code

[Code]....

and in the page load everything is fine

[Code]....

View 2 Replies

DataSource Controls :: 'SqlConnection' Is Not Defined In The Behind Code?

Oct 29, 2010

'SqlConnection' is not defined in the behind code as follows:

Source Error:

[Code]...

Source File: I:WebsitesCMPHostFox BackupDefault.aspx.vb Line: 24

Snippet reads as follows:

[Code]...

View 5 Replies

DataSource Controls :: Use ArrayList In SqlCommand

May 1, 2010

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)

View 3 Replies

DataSource Controls :: How To Set Variable In Asp:sqldatasource In Sqlcommand In C#

Jun 28, 2010

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

View 1 Replies

DataSource Controls :: How To Dump Sql Statement From Sqlcommand

Jan 13, 2010

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.

View 2 Replies

DataSource Controls :: Benefits Of Using SqlCommand.ExecuteNonQuery Instead Of â€

Mar 29, 2010

[Code]....

is used for update, insert and delete operations.Besides the fact

View 3 Replies

DataSource Controls :: Approach For Making Sqlconnection To Interact With Database?

Feb 26, 2010

I am using "ASP .Net 2.0" with "SQL Server 2005". What is better and preffered approach towards making a sqlconnection to interect with database?

1. To open new connection each time we need to interact with DB and then close the connection

2. Or to make a shared database connection for whole web application.

View 2 Replies

DataSource Controls :: Pointing To The SqlSelecting Event In The Code Behind SqlConnection?

Jan 26, 2010

I know you can point to a OnSelecting event on the aspx page datasource. But I've created my SqlDataSource in the code behind. Is there any way to point to a selecting event in the code behind (I need this to provide the parameters)? Or should I just include all my logic in the Page_Load event (where I keep my SqlConnection)Here's what I have so far:

protected void Page_Load(object sender, EventArgs e)
{
SqlCommand myCommand = new SqlCommand();

[code]...

View 1 Replies

DataSource Controls :: To Write Safe Code Sqlcommand.ExecuteNonquery?

Jan 6, 2010

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)

View 2 Replies

DataSource Controls :: How To Convert Empty Textbox Text To Null On SqlCommand

Mar 22, 2010

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]....

View 5 Replies

DataSource Controls :: Return Number Of Rows Affected For Multiple Queries In One SQLCommand?

Feb 22, 2010

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).

View 3 Replies

DataSource Controls :: Can't Use OUPUT For Declared Variables

Jun 16, 2010

I have a problem with my SQL statement with the WHERE statement and I also need to return the declared variable. and I have a function which also needs to return the returned value but it's not passed in as parameter it passed back with a variable declared in the sql statement using the Return keyword I can't use OUPUT for declared variables so if there here's my code.

[Code]....

View 3 Replies

DataSource Controls :: Bind Website To Database With The "sqlConnection"?

Feb 11, 2010

'i'm working with visual studio 2005 asp.net c#. and i want to bind my website to my database with the "sqlConnection"

how do i get and set details from the database to the website fields with the sqlCommend and ect...

View 1 Replies

DataSource Controls :: How To Retrieve Declared Product Details From Northwind With Linqdatasource

Nov 25, 2010

I wan to retrieve spesific data from northwind and list in my compare page.

in the first page i used gridview with checkboxes. all selected values get with session and then

send to my second page. I can display this values in the page but how can i retrieve all product details from my northwind db i dont know.

here is my second page code behind.

[Code]....

and aspx page

[Code]....

View 3 Replies

Static Method Can Be Declared Inside Interface?

Apr 4, 2010

Can we declare a static method inside the Interface?If not means Why?

View 4 Replies

Forms Data Controls :: Name Not Declared Yet?

Mar 11, 2011

At a bit of a loss here. As the subject says, I have a repeater control that uses the variable xmlN which is declared in my Sub Page_Load. Posted code below.

[Code]....

View 2 Replies

Access Controls Declared In TemplateColumn Of DataGrid?

Aug 24, 2010

ASCX File:

<asp:datagrid runat="server" id="gridFormFields" datakeyfield="FieldID"
autogeneratecolumns="False"
onitemcommand="gridFormFields_ItemCommand" onitemdatabound="gridFormFields_ItemDataBound">
<columns>

[Code]....

In the code behind, the Control returned by FindControl is null. Why? How can I access the buttonMoveUpFormField and buttonMoveDownFormField controls? From the code behind, is it possible to access controls which are declared in the ItemTemplate section of the TemplateColumn section of a DataGrid?

View 2 Replies

DataSource Controls :: Inside Procedure, Sql Returned Records Or Not?

May 11, 2010

inside procedure, how to know a sql returned records or not?

View 7 Replies

Vb.net - Close A Sqlconnection In .net?

May 17, 2010

i would like to know if there's something wrong in this asp.net code:

mydatareader = mycmd.executeReader()
if myDataReader.HasRow then
// Do something
end if
myConnection.Close()

If i avoid to call a "MyDataReader.Close()" does the connection close anyway ? I ask this because i'm assuming that if call a "MyConn.Close" it automatically close the associated datareader... or am i wrong ?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved