Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Saturday, March 31, 2012

table to list

this code is to bring one coloumn in a listbox... when selecting that list corresponding values for that selection should be displayed in my text boxes kept in de form please some one help me...

thanks in advance......

Dim myDB As Database
Dim myRS As dao.Recordset
Dim tdf As TableDef

Private Sub DataList1_Click()

End Sub

Private Sub EXIT_Click()
Unload Me
End Sub

Private Sub Form_Load()
Set myDB = OpenDatabase("C:\deepesh\name.mdb")
Set myRS = myDB.OpenRecordset("details", dbOpenTable)
For Each tdf In myDB.TableDefs
name1.AddItem tdf.name
Next tdf
'If myRS.RecordCount > 0 Then
'myRS.MoveFirst
'End If
If Not myRS.EOF And Not myRS.BOF Then
myRS.MoveFirst
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
myRS.Close
Set myRS = Nothing
myDB.Close
Set myDB = Nothing
End Sub

Private Sub name1_Change()
Set myRS = myDB.OpenRecordset("select name,street1,street2,city,pincode,phone,pan_number from details where name=""& List1.Text &", dbopendybaset)
myRS.FindFirst "[name] = " & name1.Text & """"
If myRS.RecordCount > 0 Then
'If myRS.NoMatch = False Then
phone.Text = myRS("phone")
street1.Text = myRS("street1")
street2.Text = myRS("sreet2")
city.Text = myRS("city")
pincode.Text = myRS("pincode")
pincode.Text = myRS.Fields(5)
End If
Set myRS = Nothing
End Subbut how to add script i don understand i am new to vb so kindly help
You will need to add a bit of javascript to your listbox. Your spectacularly unstructured code makes it a little difficult to look at, but I figure that 'name1' is the name of your listbox. Use .Attributes.Add() to have it call a bit of javascript that populates a textbox on each click event.
Ok, I'll tell you half of it, since you ought to learn.

First, find out the javascript required to populate a textbox whenever an item in a listbox is clicked. Once you find that javascript, in your codebehind, use

name1.Attributes.Add("onClick",yourjavascripthere);

Keep in mind that the exact id of the textbox must be substituted in 'yourjavascripthere'. For this, you can use string concatenation and use textbox1.ClientId to get the client id of the textbox.
i seriously didnt understand a little bit... can we addd script in vb huh???
Yes. In your codebehind, you can dynamically add javascript to one of your controls. For that, you use name1.Attributes.Add().

So for example...

textbox1.Attributes.Add("onClick","alert('hello!');");

Will cause a messagebox to appear when someone clicks on textbox1.
This is ASP.Net forum and not the VB 6 forum. Please ask the moderators to move this thread to Classic VB forum.
Good call. (slaps forehead)

Table Web Control

I'm using a Table web control to dynamically create checkboxes, and check/uncheck/enable/disable them based on values returned from different datasources. In this case, I'm using several DataTables.

I've completed the table on load, and all of the checkbox controls load up as expected, however I now need to submit any changes based on the users values. I've been googling for a good article on the Table web control but haven't found anything that will help. Does anyone know of any articles, or have sample code for maintaining state of these controls and iterating through them so I can create my dynamic SQL based on selections?

Thanks.From the SDK:

"Note: Programmatic additions or modifications to a table row or cell will not persist across posts to the server. Table rows and cells are controls of their own, not properties of the Table control. Changes to table rows or cells must be reconstructed after each post to the server."

Ok, so I think that answers my viewstate problem. I DO recreate this table on page load everytime, so I don't think I need to worry about that.

Any help on muddling through the selected checkboxes of a dynamically created table web control, would still be very beneficial to my cause.
Ugh, I'm fried here...

The viewstate will STILL be a problem, because I wasn't thinking that with each postback, my table would just be re-created, therefore I won't get the modified values on submission.

I keep talking to myself but oh well...

Just to reiterate, I need help on maintaing state for a dynamically created table web control, and how to iterate through the controls that were created in that table on postback.
Dear Forum,

Hi! It's me again!

Ok, so after a little more research I found that people are suggesting the Request.Form() to collect information about the controls. Does that sound right? I guess if you can't take advantage of viewstate in this situation, then Request.Form() is the way to go.

Taking that into consideration, I don't think I can really "iterate" through the controls in my dynamic table, but maybe create some variables that will hold the number of checkbox controls say, when I create the table. So maybe it would look something like this:

pseudocode -
' Creating the table
Dim cb as CheckBox
Dim cbCounter as Int32
'Dynamically create checkbox here and increment the checkbox counter

Then later when I retireve the values within my table...

'Go through each of the checkboxes and determine the value
for x=0 to cbCounter.Length - 1
'check the value of checkbox "x" here

Does this sound like a logical resolution? Am I taking this too far and there is an easier path that I'm missing here? Does anyone really care at this point? :)
Hi FrankWhite,

I'm having the same problem here. I'm fetching values from a MySQL database, I show them in a nice table with checkboxes. But when the user clicks "submit" my checkboxes are lost (since my table won't keep them).
So I'm looking for the same solution: how can I keep all generated checkboxes, so I can check which of them are checked by the user?

If someone has experience with this scenario and knows how it can be done, please post it here for me and FrankWhite ;)

Thanks in advance!
1. Try to stay away from dynamically creating controls that need to keep their values during postbacks.

2. Modify the way you search for information. More than 50% of programming involves just trying to find out how to do stuff. Your problem is not with viewstate, but with the ASP.NET lifecycle.

To answer both your question, you will need some patients.This article will answer your questions, but you have to read every word carefully. DONT skip to the end and read the conclusion as you will miss out on important things that you should learn.

Jagdip
(Haven't read the article yet)

I did come to a solution the other day. Basically on Page_Load my table is recreated everytime. When the submit button is pressed, I simply do Request.Form() on the checkbox controls. I don't have the code in front of me at the moment, but I basically did the following to solve my problem.

1.) Created a variable that would serve as a counter for my checkboxes.
2.) When the checkbox was created, I would give it the id: "chk_" & chkCtrls (variable that was the counter)
3.) In the btn_submit() I created a loop to iterate through each of the checkbox controls (well not really the controls, rather the # of controls). In the loop I would check if the checkbox was checked and do something according to that:

for x = 0 to chkCtrls
if Request.Form("chk_" & x) = "On" Then
'do something
end if
next

There was a lot more to it then this for my situation, but I think this will give you a good idea. Let me know if this helps, or if you figured out a different solution. In the meantime, I'll need to peep this article...
I used the same solution, I recreated my checkbox collection each time in Page_load, and used Request.Form to check wether the "check all" was checked or unchecked to set a default checked value on each checkbox (true/false). Then on the submit button I used Request.Form again to check the status of each generated checkbox by checking for controls like "chk" + intID.
This does the trick I needed very well.

I'll take a look at the article as well, in case this is not the right way of programming this :)

Thanks for the help,
Speerman
Alright, alright, I'll give you the jist of it. I'm not an expert in this (just been reading around a lot) so here goes.
Basically, the ASP.NET life cylce loads your info like this:

Page_Init
Load ViewState
Page_Load
Run any controls functions (e.g. button_click functions, etc.)

From this you can see that if you create controls dynamically, then they will be displayed on the page; but their viewstate will not be 'loaded'. What we need is a way to create the controls before the Load Viewstate state.

Solution: If you are using VS, the you know there is a region called " Web Form Designer Generated Code ". In this you will find:


'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

All you need to do is call the function that creates the dynamic controls from within the Page_Init function. That's it (i think - havent got a chance to try it).

But please, read the article. You will have a better understanding of ASP.NET which means better pages (and maybe a pay rise - you can tell why I read the aticles ;-)

HTH
Jagdip

TableAdapter: How do I create one which inserts values from a form into two tables?

I am creating a simple booking system. The system requires the users
to provide information regarding themselves and also the booking
detail. I want to send the data into two tables. One, the personalinfo
table and another bookinginfo. The bookinginfo, also has a column for
personalID which links it to the personalInfo table. How can I do this
with eiter an ASP button control use a table adapter to do it.
Sorry if this sounds trivial but I am really new to ASP and SQL.
RegardsYou'd need to simply write the data out to the table. Have a look at the
connection objects in .NET there is actually a lot of code that already does
what you want posted all over the web.
Regards,
Alvin Bruney
---
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Fendi Baba" <effendi@.epitome.com.sg> wrote in message
news:1171175411.943113.134530@.h3g2000cwc.googlegroups.com...
>I am creating a simple booking system. The system requires the users
> to provide information regarding themselves and also the booking
> detail. I want to send the data into two tables. One, the personalinfo
> table and another bookinginfo. The bookinginfo, also has a column for
> personalID which links it to the personalInfo table. How can I do this
> with eiter an ASP button control use a table adapter to do it.
> Sorry if this sounds trivial but I am really new to ASP and SQL.
> Regards
>

TableAdapter: How do I create one which inserts values from a form into two tables?

I am creating a simple booking system. The system requires the users
to provide information regarding themselves and also the booking
detail. I want to send the data into two tables. One, the personalinfo
table and another bookinginfo. The bookinginfo, also has a column for
personalID which links it to the personalInfo table. How can I do this
with eiter an ASP button control use a table adapter to do it.

Sorry if this sounds trivial but I am really new to ASP and SQL.

RegardsYou'd need to simply write the data out to the table. Have a look at the
connection objects in .NET there is actually a lot of code that already does
what you want posted all over the web.

--
Regards,
Alvin Bruney
----------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

"Fendi Baba" <effendi@.epitome.com.sgwrote in message
news:1171175411.943113.134530@.h3g2000cwc.googlegro ups.com...

Quote:

Originally Posted by

>I am creating a simple booking system. The system requires the users
to provide information regarding themselves and also the booking
detail. I want to send the data into two tables. One, the personalinfo
table and another bookinginfo. The bookinginfo, also has a column for
personalID which links it to the personalInfo table. How can I do this
with eiter an ASP button control use a table adapter to do it.
>
Sorry if this sounds trivial but I am really new to ASP and SQL.
>
Regards
>

Wednesday, March 28, 2012

TableAdapters using values

I have created a data access layer, have a datset with several tables. In VB I would like to access a the value of a particular cell, put that value into a variable. I am unsure how to do this. So far I have,

1Imports DataSet1TableAdapters2~~~~~~34Dim testID = Request("tid")56Dim levelAs Integer = 07Dim testsTableAdapterAs New TestsTableAdapter89level = testsTableAdapter.GetTestsByTestID(testID).Rows(0).Table.Columns(1)10

I know that this is incorrect, however I wish to get the value held in row 1 column 2. Any help would be much appreciated.

Hi,

Based on my understanding, you want to get the value held in particular cell by DataAdapter. If I have misunderstood you, please feel free to tell me, thanks.

 
Dim constrAs String =""'your connection stringDim connectionAs SqlConnection =New SqlConnection(constr)Dim sqlselAs String ="select * from test"Dim sdaAs SqlDataAdapter =New SqlDataAdapter(sqlsel, connection)Dim dsAs DataSet =New DataSet() sda.Fill(ds,"table")Dim levelAs Integer = ds.Tables("table").Rows(1)(2)
 Hope this can help you.

Try this

SqlConnection conn= new SqlConnection("YOUR CONNECTION STRING")
sql = "select * from TableName"
SqlDataAdapter ad = new SqlDataAdapter(sql, conn)
DataSet DS = new DataSet()

ad.Fill(DS,"TableName") // OR ad.Fill(DS.Tables(0))

Dim lvl As Integer
lvl = (int) DS.Table(0).Rows(1)


thanks for replying.

I was hoping to do it without setting a connection string or inputting SQL into the code. I want the dataset in my DAL to take care of this. Is there any way for the tableadapter to populate a new dataSet?


Please refer to this thread below

http://forums.asp.net/p/1187777/2031770.aspx#2031770

This might give you an idea

Thursday, March 22, 2012

Taking a value from a dataset

I trying to get a single values from a dataset however I keep getting the following error please help

 Function get_poll_questions() As System.Data.DataSet

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=db\database.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT top 1 * FROM tbl_poll_questions ORDER BY pol_question, rnd(pol_ID)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0)("pol_question").ToString()

return strTesting

End Function

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 116:
Line 117:
Line 118: strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0)("pol_question").ToString()
Line 119:
Line 120: return strTesting

Many thanks in advanceMake sure that the SQL has returned any data. Also make sure that pol_question is the correct name of the column.
Also, I havent seen it done like this:

strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0)("pol_question").ToString()

Try this instead:

strTESTING = DataSet.Tables("tbl_poll_questions").Rows(0).items("pol_question").ToString()

Also, since you are doing this:
dataAdapter.Fill(dataSet)

and not giving a table name...the table is not named "tbl_poll_questions". Rather, it is named just "table" or you could use the index of 0, like:

strTESTING = DataSet.Tables(0).Rows(0).items("pol_question").ToString()

In order to use that table name you would have to do:
dataAdapter.Fill(dataSet,"tbl_pol_questions")

MajorCats