473,946 Members | 6,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Data

Hello,

I have an SQL database table with 20 fields: Field_01, Field_02, etc.
I am creating a string with StringBuilder.
I want to include in my string the fields of one record of the
database.
The SQL procedure "GetOneReco rd" gets one record when its ID is givem.

So my problem is how to access each record field and use it in my
string.
For example:

MyStringBuilder .Append("<title >")
MyStringBuilder .Append(Field_0 1) <<<< Field_01 of selected
record.
MyStringBuilder .Append("</title>")

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlCo nnection(connec tionString.ToSt ring)

' Define command
Dim command As New SqlClient.SqlCo mmand
With command
.CommandText = "GetOneReco rd"
.Connection = connection
.CommandType = CommandType.Sto redProcedure
End With

' Add command parameters
With command.Paramet ers
.Add(New SqlClient.SqlPa rameter("@Id", Id))
End With

connection.Open ()
>>>>Here I need to execute the command and use all Field_##
values in my String Builder.

connection.Clos e()

How can I do this?

Thanks,
Miguel

Oct 26 '06 #1
4 1302
"shapper" <md*****@gmail. comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
I have an SQL database table with 20 fields: Field_01, Field_02, etc.
You can't be serious...! You call your fields Field_01, Field_02 etc...???

Surely not!!!
Oct 26 '06 #2
Of course not ... that was just an example.

Thatwas not even the point of my question!

Cheers,
Miguel

Mark Rae wrote:
"shapper" <md*****@gmail. comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
I have an SQL database table with 20 fields: Field_01, Field_02, etc.

You can't be serious...! You call your fields Field_01, Field_02 etc...???

Surely not!!!
Oct 26 '06 #3
Howdy shapper,

You're asking about basics

1. use data reader

dim reader as SqlDataReader
Dim field01Value As String
Dim field02Value As Integer

Try
connection.Open ()
reader = command.Execute Reader()

If reader.Read() Then

field01Value = CType(reader("f ield01"), String)
field02Value = CType(reader("f ield02"), Integer)
' etc.

End If

Catch ex As Exception
Throw
Finally
If Not reader Is Nothing Then
reader.Close()
End If
connection.Clos e()
End Try
reader.Close()

2. Use datatable

connection.Open ()
adapter.Fill(ta ble)
Catch ex As Exception
Throw
Finally
connection.Clos e()
End Try

If table.Rows.Coun t 0 Then
Dim row As DataRow = table.Rows(0)
myStringBuilder .Append(row("Fi eld01"))
' etc
End If

3. i see you're trying to build xml using values from MSSQL database - you
may use FOR XML statement i.e.:

select Field01 as Title, Field02 as FirstName from TableName WHERE RecordId
= 2
for xml auto, ELEMENTS

hope this helps
--
Milosz Skalecki
MCP, MCAD
"shapper" wrote:
Hello,

I have an SQL database table with 20 fields: Field_01, Field_02, etc.
I am creating a string with StringBuilder.
I want to include in my string the fields of one record of the
database.
The SQL procedure "GetOneReco rd" gets one record when its ID is givem.

So my problem is how to access each record field and use it in my
string.
For example:

MyStringBuilder .Append("<title >")
MyStringBuilder .Append(Field_0 1) <<<< Field_01 of selected
record.
MyStringBuilder .Append("</title>")

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlCo nnection(connec tionString.ToSt ring)

' Define command
Dim command As New SqlClient.SqlCo mmand
With command
.CommandText = "GetOneReco rd"
.Connection = connection
.CommandType = CommandType.Sto redProcedure
End With

' Add command parameters
With command.Paramet ers
.Add(New SqlClient.SqlPa rameter("@Id", Id))
End With

connection.Open ()
>>>>Here I need to execute the command and use all Field_##
values in my String Builder.

connection.Clos e()

How can I do this?

Thanks,
Miguel

Oct 26 '06 #4
Shapper,

MyStringBuilder .Append("<title >")
MyStringBuilder .Append(Field_0 1) <<<< Field_01 of selected
record.
MyStringBuilder .Append("</title>")

Not to be rude, but string manipulation is the absolute WORST way to build
up xml or html.
This is very "asp-ish" and very hacky.
One way, among several different legimate methods for creating xml is
http://msdn2.microsoft.com/en-us/lib...r_methods.aspx
XmlWriter.

Or, as someone says, you can get Xml out of the database (Sql Server and
Oracle) by using their languages.

...

If you're doing HTML, then you'll use
DataGrid, Repeater, DataList in 1.1
GridView, Repeater in 2.0.
response.write "<table><tr><td >" is NOT the way to go.


"shapper" <md*****@gmail. comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
Hello,

I have an SQL database table with 20 fields: Field_01, Field_02, etc.
I am creating a string with StringBuilder.
I want to include in my string the fields of one record of the
database.
The SQL procedure "GetOneReco rd" gets one record when its ID is givem.

So my problem is how to access each record field and use it in my
string.
For example:

MyStringBuilder .Append("<title >")
MyStringBuilder .Append(Field_0 1) <<<< Field_01 of selected
record.
MyStringBuilder .Append("</title>")

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlCo nnection(connec tionString.ToSt ring)

' Define command
Dim command As New SqlClient.SqlCo mmand
With command
.CommandText = "GetOneReco rd"
.Connection = connection
.CommandType = CommandType.Sto redProcedure
End With

' Add command parameters
With command.Paramet ers
.Add(New SqlClient.SqlPa rameter("@Id", Id))
End With

connection.Open ()
>>>>Here I need to execute the command and use all Field_##
values in my String Builder.

connection.Clos e()

How can I do this?

Thanks,
Miguel

Oct 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8024
by: Chris | last post by:
Could someone please provide me an effective means of exporting data from a data set (or data grid) to Excel?
9
3324
by: Tony Lee | last post by:
Some time a ago, on this newsgroup the following comments were made in recommending good references for Access (2003) >I used to recommend Dr. Rick Dobson's, "Programming Access <version>" for >people moving from power user to developer, but now I suggest you browse >it, >too. It strongly emphasizes ADO, which knowledgeable Microsoft insiders no >longer recommend, and the Access ADP client to SQL Server. He writes well, >and is a good...
1
17299
by: djozy | last post by:
Please, I want to insert data into SQL Server database. I know for this commmand: SqlCommand myCommand= new SqlCommand("INSERT INTO table (Column1, Column2) " + "Values ('string', 1)", myConnection); ,but how to insert,lets say,a string from textbox1? Or datetime from textbox2? Thank you djozy
1
6915
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by itself (asp.net recycled?); it also can be solved by restarting IIS. Any ideas what cause(s) this to happen? System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr) at...
0
5695
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
3
2064
by: bbernieb | last post by:
Hi, All, Is it possible to access a variable inside of a data binding, without the variable being out of scope? (Note: On the DataBinder line, I get an error message that says "Name 'i' is not declared". The data bind is for a DataList.)
5
2236
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and then..... what should I do?
5
1802
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to 1997 and back. Unfortunately, it seems does reflect the change on my web form. Perhaps it's caching the data retrieved by the SQLDataAdapter? (All of my code is generated by VS.NET '03. FYI, it works fine when I test on my developer...
14
14682
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control so I get the ObjectDataSource. No problem ..... ObjectDataSource src = .... //is ok i have it
0
2090
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media. Call for a free consultation. http://a.uuload.com/Computer-Data-Recovery.htm LiveVault's Online Recovery Service Protect vital data with LiveVault's offsite backup and data storage. http://a.uuload.com/Computer-Data-Recovery.htm
0
10686
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9886
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7423
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6111
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4939
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3539
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.