Create data capture forms ...

  • Thread starter Thread starter saturnius
  • Start date Start date
S

saturnius

Hello,
I have to create data input forms to capture data (for sql server). I
was just wondering weather there is an automated way (like using the
datagrid) to link the "textbox.text" with the update command of the
data adapter ….

Many thanks in advance!
 
Hi Saturnius,

A sample I once made, (when you do not have that date problems or other
conversions, you can skip that Mybinding and add the bindings direct as a
string to the databinding. And skip all other things. (It is thna one line
of code)

I hope this helps

Cor

\\\
Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
//
 
Hello,
Thanks for the answer Cor (but this code is a bit to heavy for me ...)
I did something else:
- I can read the table names form the database
- I create Textboxes dynamic
- BUT how to read the data ....?????

Here goes the Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Try
Me.SqlConnection1.Open()
Dim cmd = New System.Data.SqlClient.SqlCommand("SELECT
* FROM myinformation", Me.SqlConnection1)
Dim Rd = cmd.ExecuteReader(CommandBehavior.SchemaOnly)
dt = (Rd.GetSchemaTable())
Rd.Close()
Me.SqlConnection1.Close()

Dim iCount As Integer = dt.Rows.Count - 1

Dim t As New Table
t.ID = "dyntab"
Dim i As Integer
Dim j As Integer

For i = 0 To iCount
Dim r As New TableRow
r.ID = "r" & i.ToString
Dim c As New TableCell
c.ID = "c" & i.ToString
c.Text = dt.Rows(i).Item(0)
r.Cells.Add(c)
Dim tc As New TableCell
Dim tb As New TextBox
tc.Controls.Add(tb)
tc.ID = dt.Rows(i).Item(0)
r.Cells.Add(tc)
t.Rows.Add(r)
Next
Panel1.Controls.Add(t)
Catch ex As Exception
Label1.Text = ex.Source & "--" & ex.Message
End Try
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = Panel1.Controls.Count
'' How to get the value of the textbox back????
End Sub
 
Hi Saturnius,

When you are posting to this newsgroup than the default form is a
windowforms, what I did sent you does not work on a webform.

Your question is easy to answer.
Dim a As String = Me.TextBox1.Text

I saw some small errors in your code, the one I saw I have tried to correct

I hope this helps,

Cor

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Try
Me.SqlConnection1.Open()
Dim cmd as New System.Data.SqlClient.SqlCommand("SELECT
* FROM myinformation", Me.SqlConnection1)
Dim Rd as System.Data.SqlClient.SqlDatareader
Rd = cmd.ExecuteReader(CommandBehavior.SchemaOnly)
dt = Rd.GetSchemaTable()
Rd.Close()
Me.SqlConnection1.Close()

Dim iCount As Integer = dt.Rows.Count - 1

Dim t As New Table
t.ID = "dyntab"
Dim i As Integer
Dim j As Integer

For i = 0 To iCount
Dim r As New TableRow
r.ID = "r" & i.ToString
Dim c As New TableCell
c.ID = "c" & i.ToString
c.Text = dt.Rows(i).Item(0).toString
r.Cells.Add(c)
Dim tc As New TableCell
Dim tb As New TextBox
tc.Controls.Add(tb)
tc.ID = dt.Rows(i).Item(0).toString
 
Hi,
I got the answer from another newsgroup:
1.Create with ID - tb1.Id = "ControlID"
2.Button Click Event - Request.Form("ControlID")

Cheers Saturnius ;-)
 
Back
Top