Hi,
This are the lines I have now:
SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable";
SqlDataSource1.SelectParameters.Add(new Parameter("RangeId",
TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot of
samples on the internet but could not find the solution.
Thanks!
Arjen 7 39232
Arjen,
If you don't intend to use the SQLDataSource resultset to bind to some
control such as a gridview, you would probably be better off using a
SqlCommand object directly with the ExecuteScalar method, which is much more
efficient for single values.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Arjen" wrote:
Hi,
This are the lines I have now:
SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable";
SqlDataSource1.SelectParameters.Add(new Parameter("RangeId",
TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot of
samples on the internet but could not find the solution.
Thanks!
Arjen
Hi Peter,
I'm only using this for a simple application, one that I only will use this
month.
With the datasource object I also want to update the table. Therefor I want
to keep the code style consistent.
Do you have an example how to use the select and update method with the
datasource object?
Thanks,
Arjen
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comschreef in
bericht news:75**********************************@microsof t.com...
Arjen,
If you don't intend to use the SQLDataSource resultset to bind to some
control such as a gridview, you would probably be better off using a
SqlCommand object directly with the ExecuteScalar method, which is much
more
efficient for single values.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Arjen" wrote:
>Hi,
This are the lines I have now: SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable"; SqlDataSource1.SelectParameters.Add(new Parameter("RangeId", TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot of samples on the internet but could not find the solution.
Thanks! Arjen
"Arjen" <bo*****@hotmail.comwrote in message
news:f4**********@news2.zwoll1.ov.home.nl...
Hi,
This are the lines I have now:
SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable";
SqlDataSource1.SelectParameters.Add(new Parameter("RangeId",
TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot
of samples on the internet but could not find the solution.
Why don't you use a DataReader?
MyDataReader[1] // equals field two of the fields being pulled back in the
recordset record.
Or you can use MyDataReader['caseid'] // if field 0 is the record's key.
You might have to go through a Convert to set a database field to the proper
variable type.
So in your case, the Reader is only to read one record and hit EOF.
SqlConnection MyConnection = new SqlConnection(@"Data Source=(local);
Initial Catalog = CaseManager; Integrated Security=true");
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo",
MyConnection);
SqlDataReader MyDataReader =
MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);
while (MyDataReader.Read())
{
Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]);
}
MyConnection.Close();
Hi Arnold,
Thanks for your response.
I want to use the SqlDataSource. I know my parameter, my command, but don't
know how to get the row.
SqlDataSource1.Select???
Can you tell me that?
Arjen
"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:eg****************@TK2MSFTNGP06.phx.gbl...
>
"Arjen" <bo*****@hotmail.comwrote in message
news:f4**********@news2.zwoll1.ov.home.nl...
>Hi,
This are the lines I have now: SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable"; SqlDataSource1.SelectParameters.Add(new Parameter("RangeId", TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot of samples on the internet but could not find the solution.
Why don't you use a DataReader?
MyDataReader[1] // equals field two of the fields being pulled back in
the recordset record.
Or you can use MyDataReader['caseid'] // if field 0 is the record's key.
You might have to go through a Convert to set a database field to the
proper variable type.
So in your case, the Reader is only to read one record and hit EOF.
SqlConnection MyConnection = new SqlConnection(@"Data Source=(local);
Initial Catalog = CaseManager; Integrated Security=true");
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo",
MyConnection);
SqlDataReader MyDataReader =
MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);
while (MyDataReader.Read())
{
Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]);
}
MyConnection.Close();
The ASP.NET QUICKSTARTS is the place to look first for all of this kind of
stuff. http://quickstarts.asp.net/QuickStar...atasource.aspx
It also installs with the products if you select it to.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Arjen" wrote:
Hi Arnold,
Thanks for your response.
I want to use the SqlDataSource. I know my parameter, my command, but don't
know how to get the row.
SqlDataSource1.Select???
Can you tell me that?
Arjen
"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:eg****************@TK2MSFTNGP06.phx.gbl...
"Arjen" <bo*****@hotmail.comwrote in message
news:f4**********@news2.zwoll1.ov.home.nl...
Hi,
This are the lines I have now:
SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable";
SqlDataSource1.SelectParameters.Add(new Parameter("RangeId",
TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot
of samples on the internet but could not find the solution.
Why don't you use a DataReader?
MyDataReader[1] // equals field two of the fields being pulled back in
the recordset record.
Or you can use MyDataReader['caseid'] // if field 0 is the record's key.
You might have to go through a Convert to set a database field to the
proper variable type.
So in your case, the Reader is only to read one record and hit EOF.
SqlConnection MyConnection = new SqlConnection(@"Data Source=(local);
Initial Catalog = CaseManager; Integrated Security=true");
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo",
MyConnection);
SqlDataReader MyDataReader =
MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);
while (MyDataReader.Read())
{
Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]);
}
MyConnection.Close();
Hi,
Thanks!
Finally it works... :)
Arjen
"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:eg****************@TK2MSFTNGP06.phx.gbl...
>
"Arjen" <bo*****@hotmail.comwrote in message
news:f4**********@news2.zwoll1.ov.home.nl...
>Hi,
This are the lines I have now: SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable"; SqlDataSource1.SelectParameters.Add(new Parameter("RangeId", TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot of samples on the internet but could not find the solution.
Why don't you use a DataReader?
MyDataReader[1] // equals field two of the fields being pulled back in
the recordset record.
Or you can use MyDataReader['caseid'] // if field 0 is the record's key.
You might have to go through a Convert to set a database field to the
proper variable type.
So in your case, the Reader is only to read one record and hit EOF.
SqlConnection MyConnection = new SqlConnection(@"Data Source=(local);
Initial Catalog = CaseManager; Integrated Security=true");
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo",
MyConnection);
SqlDataReader MyDataReader =
MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);
while (MyDataReader.Read())
{
Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]);
}
MyConnection.Close();
"Arjen" <bo*****@hotmail.comwrote in message
news:f4**********@news5.zwoll1.ov.home.nl...
Hi,
Thanks!
Finally it works... :)
Arjen
You are welcomed. :)
"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:eg****************@TK2MSFTNGP06.phx.gbl...
>> "Arjen" <bo*****@hotmail.comwrote in message news:f4**********@news2.zwoll1.ov.home.nl...
>>Hi,
This are the lines I have now: SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable"; SqlDataSource1.SelectParameters.Add(new Parameter("RangeId", TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot of samples on the internet but could not find the solution.
Why don't you use a DataReader?
MyDataReader[1] // equals field two of the fields being pulled back in the recordset record.
Or you can use MyDataReader['caseid'] // if field 0 is the record's key.
You might have to go through a Convert to set a database field to the proper variable type.
So in your case, the Reader is only to read one record and hit EOF.
SqlConnection MyConnection = new SqlConnection(@"Data Source=(local); Initial Catalog = CaseManager; Integrated Security=true");
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo", MyConnection); SqlDataReader MyDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConn ection);
while (MyDataReader.Read()) { Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]); }
MyConnection.Close();
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Swetha |
last post by:
Hello
I have a DropDownList that I am populating using the following
SqlDataSource:
<asp:DropDownList ID="parentIDDropDownList" runat="server"
DataSourceID="SqlDataSource3"...
|
by: staeri |
last post by:
Hello!
I would like to set the SqlDataSource in the code behind file and not
to have it in the aspx file. How can I do that?
Regards,
Staeri
|
by: Dorte |
last post by:
Hi,
Could someone help me with a couple of links to SqlDatasource documentation
on how to use the Gridview and SqlDatasource components in code behind?
Basically I'm missing some documentation...
|
by: phil |
last post by:
Hi,
The connection and DeleteCommand of a gridview are defined in the aspx file
like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"...
|
by: thomson |
last post by:
Hi All,
i do have an application that searches the databse, For eg, i
do,
SqlHelper.ExecuteReader("","") this is the point where i call the
stored procedure to fetch the data from the database,...
|
by: jmacduff |
last post by:
Big question: How to enable edit/update commands to work when setting
the sqldatasource select command from code behind.
Details:
I have a GridView using a sqldatasouce with the select and...
|
by: ADAC |
last post by:
I am very familiar with Visual studio 2003 and trying to get a handle on 2005
I can set up the datasource and make it work fine when I databind it to a control like a gridview or details view....
|
by: DotNetNubie66 |
last post by:
I have a Master page that wraps my content pages, on one page I have a FormView that is tied to an ObjectDataSource and has textbox and calendar controls bound to the datasource. My problem is this,...
|
by: markpringle |
last post by:
This is my sqldatasource this is on the page:
<asp:sqldatasource runat="server" ID="DS_CheckUserName"
ConnectionString="<%$ ConnectionStrings:SQL2005_355184_ConnectionString %>"
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |