Jump to content

how can I fill a variable from a filed of a DB?


Recommended Posts

ok Found This code. it is use full I think :) .

<script  runat="server">sub Page_Load	  Dim MyConnection As OleDbConnection	  Dim MyCommand As OleDbDataAdapter	  dim MyDataset As Data.DataSet	  dim MyTable As Data.DataTable	  dim loop1, numrows As Integer	  dim sqlstr As String	  		sqlstr = "SELECT * FROM barname"	  	  ' Create a connection to the data source. 	  'MyConnection = New OleDbConnection("Provider=SQLOLEDB;" _	   '  & "server=localhost;"Integrated Security=SSPI;" _ 		' & "Initial Catalog=Northwind")		 	  MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data/barnameHaftegi1.mdb"))	  ' Create a Command object with the SQL statement.	  MyCommand = New OleDbDataAdapter(sqlstr, MyConnection)	  ' Fill a DataSet with data returned from the database.	  MyDataset = New Data.DataSet		MyCommand.Fill(MyDataset)	  	  ' Create a new DataTable object and assign to it	  ' the new table in the Tables collection.	  MyTable = New Data.DataTable	  MyTable = MyDataset.Tables(0)	  ' Find how many rows are in the Rows collection 	  ' of the new DataTable object.	  numrows = MyTable.Rows.Count	   If numrows = 0 then		 Response.Write("<p>No records.</p>")	  Else		 Response.Write("<p>" & Cstr(numrows) & " records found.</p>")		 For loop1 = 0 To numrows - 1			' Print the values of the two columns in the Columns			' collection for each row.			Response.Write(Server.HtmlEncode(MyTable.Rows(loop1).Item("Class")) _			   & " " & Server.HtmlEncode(MyTable.Rows(loop1).Item("dayweek")) & "<br>")a= Server.HtmlEncode(MyTable.Rows(loop1).Item("Class")b= Server.HtmlEncode(MyTable.Rows(loop1).Item("dayweek"))		 Next loop1	  End If	  Response.Write("<p>End of data.</p>")   end sub</script>


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...