472,805 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 "GetOneRecord" 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_01) <<<< Field_01 of selected
record.
MyStringBuilder.Append("</title>")

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlConnection(connectionString.ToString)

' Define command
Dim command As New SqlClient.SqlCommand
With command
.CommandText = "GetOneRecord"
.Connection = connection
.CommandType = CommandType.StoredProcedure
End With

' Add command parameters
With command.Parameters
.Add(New SqlClient.SqlParameter("@Id", Id))
End With

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

connection.Close()

How can I do this?

Thanks,
Miguel

Oct 26 '06 #1
4 1263
"shapper" <md*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.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.googlegr oups.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.ExecuteReader()

If reader.Read() Then

field01Value = CType(reader("field01"), String)
field02Value = CType(reader("field02"), Integer)
' etc.

End If

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

2. Use datatable

connection.Open()
adapter.Fill(table)
Catch ex As Exception
Throw
Finally
connection.Close()
End Try

If table.Rows.Count 0 Then
Dim row As DataRow = table.Rows(0)
myStringBuilder.Append(row("Field01"))
' 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 "GetOneRecord" 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_01) <<<< Field_01 of selected
record.
MyStringBuilder.Append("</title>")

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlConnection(connectionString.ToString)

' Define command
Dim command As New SqlClient.SqlCommand
With command
.CommandText = "GetOneRecord"
.Connection = connection
.CommandType = CommandType.StoredProcedure
End With

' Add command parameters
With command.Parameters
.Add(New SqlClient.SqlParameter("@Id", Id))
End With

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

connection.Close()

How can I do this?

Thanks,
Miguel

Oct 26 '06 #4
Shapper,

MyStringBuilder.Append("<title>")
MyStringBuilder.Append(Field_01) <<<< 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.googlegr oups.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 "GetOneRecord" 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_01) <<<< Field_01 of selected
record.
MyStringBuilder.Append("</title>")

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlConnection(connectionString.ToString)

' Define command
Dim command As New SqlClient.SqlCommand
With command
.CommandText = "GetOneRecord"
.Connection = connection
.CommandType = CommandType.StoredProcedure
End With

' Add command parameters
With command.Parameters
.Add(New SqlClient.SqlParameter("@Id", Id))
End With

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

connection.Close()

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
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
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...
1
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)",...
1
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...
0
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...
3
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...
5
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...
5
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...
14
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...
0
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....
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.