testing the value of a database field

I am converting a site to asp.net and have run into the following problem.

in ASP I used to text if a field from a database was empty with the following


 Set objConn1 = Server.CreateObject("ADODB.Connection")
 objConn1.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & _
  Server.MapPath("../e_courses.mdb") & ";"
  objConn1.Open
  Set objRS1 = Server.CreateObject("ADODB.Recordset")
  strSQL1 = "SELECT * FROM RCe_courses WHERE ID =  "& searchid & ""
 objRS1.CursorLocation = 3
 objRS1.Open strSQL1, objConn1

 
<% if  objRS1("Course_Name") <> "" then  %> 

where objRS1 was the name of the recordset.  I am now connecting to the database using the following

Sub Page_Load(Src As Object, E As EventArgs)
If Not IsPostBack Then

dim Connect AS OleDbConnection = New OleDbConnection
dim Adapter As OleDbDataAdapter = New OleDbDataAdapter
Dim DynamicPAgesDS as DataSet = new DataSet
Dim ConnectString, SelectStatement As String
Dim Category As String

SelectStatement = "ELECT * FROM RCe_courses WHERE id=114"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data

Source=c:\inetpub\wwwroot\regents2005\e_courses.mdb"
Connect.connectionString =ConnectString
Adapter.SelectCommand = new OleDbCommand(Selectstatement, Connect)
Adapter.SelectCommand.Connection.Open
Adapter.Fill(DynamicPAgesDS, "PDs")
rcdynamicpage.DataSource = DynamicPAgesDS.Tables("PDs")
Page.DataBind
Adapter.SelectCommand.Connection.close
End If
End Sub

and then want to test whether the course name field is blank as above. Any help would be great

Dr JOD





0
DrJod
8/24/2005 10:50:43 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

5 Replies
445 Views

Similar Articles

[PageSpeed] 3

The following code will check the first row, first column in ur dataset datatable,

IF DynamicPAgesDS.Tables("PDs").Rows(0)(0) = DBNull.Value Then
'---Do some staff

End IF

is that what u want?

regards
ASP.NET Hosting (HostingFest)
0
smiling4ever
8/25/2005 3:09:31 AM
Thanks a lot thats nearly it.  Although I need to check each record in the table and then write it out. so in phydo code its someting like this

while there are more records do

IF DynamicPAgesDS.Tables("PDs").Rows(current record)(currentrecord) <> DBNull.Value Then
write out  DynamicPAgesDS.Tables("PDs").Rows(current record)(currentrecord)
write out some html
End IF

end while

is that clearer?

many thanks
0
DrJod
8/25/2005 6:18:41 AM
Dim LastItem as integer = DynamicPAgesDS.Tables("PDs").Rows.count

For Counter as integer = 0 To LastItem

IF DynamicPAgesDS.Tables("PDs").Rows(Counter)(currentrecord) <> DBNull.Value Then

Response.write(DynamicPAgesDS.Tables("PDs").Rows(Counter)(currentrecord))

End IF


Next


regards
HTH
ASP.NET Hosting (HostingFest)
0
smiling4ever
8/25/2005 11:09:13 PM
Thanks you are a star.  Just a few things now.  Is currentrecord a colum number and if so can I just set it as a number. Secondly is it possible to just test one particluar field and write out only the contents of that field?

Many thanks, I think I am nearly there.

James
0
DrJod
8/26/2005 9:53:15 AM
You can refer to the column by name or by number. But if u need performance call it by the ordinal number. 

For your second question, if i understand u well, then, you have a table that u can iterate as u want in it.

regards
HTH
ASP.NET Hosting (HostingFest)
0
smiling4ever
8/26/2005 10:57:48 AM
Reply:

Similar Artilces:

Get the value of field from database in RowUpdating
When using RowDataBound, I can get the value of a field from the database like:  protected void grid1_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.RowType == DataControlRowType.DataRow) {  if ((DataBinder.Eval(e.Row.DataItem, "DatabaseField")) . . . .   <<< field from database How can I do the same with RowUpdating: protected void grid1_RowUpdating(object sender, GridViewUpdateEventArgs e){if ((DataBinder.Eval(e. ???????????????????/    <<<<< can I get the value from the database he...

Get value of database field in DataList
In VB, I would use this to get the database field, . . . "Size2" in this case: protected void listGifts_ItemDataBound . . . .   If DataBinder.Eval(e.Item.DataItem, "Size2".ToString) = "Card" Then How do I do the same thing in C#?      thanks    This should workif(DataBinder.Eval(e.Item.DataItem,"Size2").ToString() == "Card"){    //your code }Regards,PrashantDont forget to click "Mark as Answer" on the post that helped you. Tryif (DataBinder.Eval(e.Item.Dat...

how can I get the value of the field in the database?
When I use sqldatareader get a sql query result from sqlcommand how can I get the value of the some special field I want to get?I am new to asp.net Thanks for man who want to help me! Wuhan, Hubei, China Hello, once you getthe datareader you do it like this: reader.GetString(2); // this will get u column number 2 in the row which is of type string reader.GetInt32(0); //this will get u column number 0 in the row which is of type int For more info on SQLDataReader, check this WebSite. Good Luck.Bilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

How to pass in value to javascript from database or let javascript to get value from database?
I am trying to use google map api to do some web based application.On the map, the javascript needs latitude and longitude from database to draw a marker on page load, I am wondering how can I get the data from database to do that? The map part will be like a image, won't change.Do I need Ajax?Thank you.  hanxiao:I am trying to use google map api to do some web based application.On the map, the javascript needs latitude and longitude from database to draw a marker on page load, I am wondering how can I get the data from database to do that? The map part will be like a image, won&...

How to get the value from a database field having text datatype
Hello I want to retrieve the data of a text datatype field in a sqlserver table in a datawindow which has more than 7000 characters. On retrieveing the in a datawindow it gives an error message of data conversion. column specification shows the limit of char(4099).I tried the same on varchar but still the data is not retrieved . Please suggest me how to get the that record in the datawindow. Jayesh ---------------------------------------------------------------------------- ---- begin 666 p.gif M1TE&.#EAZ $O`-4M`$,O#_____WZV $``&9D8.;GYXV+B#W!]*5M`>...

Insert NULL value into datetime field of Oracle database
 Hi all,I have a form which has a textbox where a date is entered by the user - this field is not compulsory so if it is left blank I want to store it in the table as nothing. However, when I use the code below it enters 01/01/0001 instead of nothing. I have tried various other options Endate.MinValue and EndDate = System.DBNull.Value (this throws an error)Im stumped. Anyone have any ideas as to how I can enter a blank value into a date field in my oracle table? Would prefer to do it before I go near the sql Insert (so in my vb.net code) because thats done using a stored procedure and w...

Retrieve a database value, if its equals to 1 hide a control (getting started)
Hi is it possible to retrieve a value from the database, and if its equals to 1 then hide a control (textbox). The value i am trying to get is here;private void DisplaySelectedRecord(DataView dv) {if (dv[0]["Rate_Active"] != null && dv[0]["Rate_Active"] != System.DBNull.Value)this.CheckBox1.Checked = Convert.ToBoolean(clsDHOC.Nz2ZeroString(dv[0]["Rate_Active"]));     }   And in page load i want it that if Rate_Active is 1 then the textbox is hidden on page load.  Why not create a private field in your class , assign your rat...

How to get the value of a textbox that has been added to a template field in a gridview. VB.Net
I have a gridview that shows products, description, price. I have added a Buttonfield and a TemplateField that has a Textbox with the id QuantityTextBox.What I am trying to do is get the value of the Quantity TextBox in the RowCommand event of the gridview. I can get the price but need to get the quantity also. To get the price I used ItemPrice = Server.HtmlDecode(row.Cells(5).Text) My template field is cell 6 but the above routine does'nt work. Any help would be greatly appreciated.Dan5150www.5150creations.com Hiuse this: VB:  Protected Sub GridView1_RowCommand(ByVal ...

Get tables and fields from Informix database using VB.NET 2005
Hi, I'm relatively new to VB.NET 2005 Express, and I've managed to connect to an Informix database to display the contents of a specific table in a DataGridView. What I am struggling with is getting the table and fields names from the database, and putting the information into a TreeView so that the user can select the table in the tree, and update the grid with that selected table - but I can't seem to get it to collect the schema information. Ideally, I'd like to have the first node on the tree as the database name, followed by nodes for the table name, and the...

Way to get Original value of the field into computed field
Hello, My Environment is PB10. Is there any way to get the orinal value (Similar to the Original buffer value in olden days) of the field into computed field. Thanks, Sra "Sravan" <sr.100102@gmail.com> wrote in message news:121a4797-cc11-4927-8613-ba3f69a6e009@e31g2000vbm.googlegroups.com... > Hello, > My Environment is PB10. Is there any way to get the orinal value > (Similar to the Original buffer value in olden days) of the field into > computed field. Just add ".original" to the column name. E.g., transaction_date.original ...

DropDownLists w/ Database Values - NOT Getting Values
I have a web form for entry and update purposes. On the form, I have some dropdownlists that allows the user to enter one of three options. When users need to update the values in the database, I would like the values from the database to be shown. I believe my logic is correct, but nothing is shown on Page_Load, i.e. the dropdownlists are blank! Here is part of my code: 'Only part of the code is shown for brevity Sub BindData() If Not IsPostBack Then ddlQuestion1.Items.Add(New ListItem("N/A", 1)) ddlQuestion1.Items.Add(New ListItem("Ye...

get the values reflected from database table as soon as the value changed!
hai, if the admin changes the value at the database table then it should be reflected to all the pages which is viewing that particular record. We should not use any frequent refresh from the browser. The pages get refreshed as soon as the values changed at database. Thanks in advance Bye   I don't think it can be done. web application is stateless, web client (browser) and web server lost connection once content downloaded, the web server can not "Push" content to client, it must be "Pulled" by web client (browser).Richard XinMCAD(charter member),MCDBA,MCSDWeb Site: www.richar...

Drop down list in Form view returns error when value in bound field (data binding
I get the following error when I click edit to edit the details in the web form:'ddlUserRestrictionType' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value  I would like it to accept any value which currently exists in the database. Is this easily achievable? With what you've posted, all I can tell is that you are trying to set the SelectedValue of a ddl to a value that does not exist in the list.  It would be helpful if you can post some code and the expected values of this control.~ Timwww.bucketo...

getting value 1 from a selected checkbox & saving the value into a database
Hi, I m new to ASP... I m building a page with few checkboxes & text boxes.. its a simple checklist you can say.. However, what i am looking for is when a check box is checked & the submit button is clicked, the value of that checkbox as 1 should be saved in the database. How to acheive this... any help would be really appreciated... Thanks Aadil  in the buttons click event look and see if the check boxes are checked and save in the db if so  if(chk1.Checked) {         //save in db      }Mike Starkey MCP, MCTS Hi Aadil you c...

Web resources about - testing the value of a database field - asp.net.getting-started

Database - Wikipedia, the free encyclopedia
... requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. Database ...

Database - Wikipedia, the free encyclopedia
A database is an organized collection of data . The data are typically organized to model aspects of reality in a way that supports processes ...

ERISA and All Claim databases
... laws, on the books in 18 states, requiring self-insured employers to report data about the prices they pay to “all payer claims databases.” ...

Sanders’ campaign looses access to N.H. Democratic voter database - The Boston Globe Sanders’ campaign ...
... the presidential campaign of US Senator Bernie Sanders has been denied access to the New Hampshire Democratic Party’s valuable voter database ...


Under pressure, DNC restores Bernie Sanders campaign's access to their database - Videos - CBS News
A strange twist in the race for the democratic presidential nomination: the campaign of Vermont Senator Bernie Sanders has filed a complaint ...

Over 680TB of data exposed in MongoDB databases
There are at least 35,000 publicly accessible and insecure MongoDB databases on the Internet, and their number appears to be growing. Combined ...

Database error publishes data of 3 million Hello Kitty fans
Online researcher Chris Vickery uncovered a database this weekend containing the personal information of 3.3 million accounts associated with ...

MacKeeper Leak Highlights Danger of Misconfigured Databases
The Shodan port-scanning service finds at least 35,000 MongoDB databases accessible without a password.

OracleVoice: Oracle Challenges SAP On In-Memory Database Claims
Companies that run SAP’s applications should know that most of those applications can perform much better on Oracle Database than on any other ...

Resources last updated: 12/27/2015 4:38:41 PM