Loading

Setting Text Programmatically of a Databound TextBox

Submitted by: 


Today I want to share with you what I have discovered in setting a text or value in databound textbox in Visual Basic .NET. I almost spend a day figuring out how to do this. While the internet is my assistant all the time, sometimes it is inevitable that the information is outdated and we cannot find the correct answer as expected.

Scenario

You bound a TextBox using a DataSet and you want to change the value to something like an auto-generated key. While this can be done easily as we may think like the following code:

InvoiceTextBox.Text = "INV-0001"

But the above code will not turn your textbox into “INV-0001” as the new value.

If you are using a bound control like textbox the following code is the right answer:

  InvoiceDataSet.Invoice.InvoiceNoColumn.DefaultValue = "INV-0001"

You need to call the name of the dataset followed by the table name and the field.

Dataset: InvoiceDataSet
Table: Invoice
Field: InvoiceNoColumn




Comments

Please let me know how to install sql server on win vista because when I install only creation of instance come and there is no window for sql manager... Pls Help

ghostEncryption's picture

I supposed to displayed the Sales Details and get the Total Sales using 2 DatePickers(FromDate and ToDate) and Display details to datagrid and Total Sales to a Label Control..but,,,this error will came out everytime i clicked the command button: here's my code:

If FromDate > ToDate Then
MsgBox "From Date must be less than To Date." & vbCrLf & "Cannot display.!", vbExclamation, "FAILED"
Exit Sub
Else
'***********this portion displays details to the datagrid
ghost = "Select * from QrySalesDetails where DatePurchased >= '" & FromDate & "' and DatePurchased <='" & ToDate & "' "
Adodc2.RecordSource = ghost
Adodc2.Refresh
'**********this will be the computation for totalsales
Dim i As Integer
Dim TAmt As Currency
TAmt = 0
i = 0
DataGrid3.Col = 6
For i = 0 To DataGrid3.ApproxCount - 1
DataGrid3.Row = i
TAmt = TAmt + Val(DataGrid3.Columns(6).Text)
Next
Label3 = Format(TAmt, "##,##0.00")

End If
'************then, this will be the Error

Run-time error '6148': Invalid Row number

.......Pls help how to solve this problem,"need this urgent..,pls,"

ghostencryption

admin's picture

On which line the error occurs?

the error on this Code..Datagrid3.Row = i

admin's picture

I'm wondering why you use DataGrid3.ApproxCount - 1 in this line:

For i = 0 To DataGrid3.ApproxCount - 1

I think you need to use the recordcount of the Adodc and not he ApproxCount of DataGrid.

can u pls Correct that line of Code Sir.?can u give me a sample code to that,?

hi sir, ive been searching the site to find a similar program for our software engineering subject, im a junior student taking up BS in IT..so this is my problem..we're about to make a system and i just wanna ask your help if you have an idea about this...
we proposed a health center automation system.. one of the key features of this is system is to notify the system administrator whenever a there is a scheduled patient. for example, if 10 patient has a schedule check up on friday, the system will notify the administrator about this 3 days before the schedule and ask him to remind the patients.if he wont check this reminders the system will still do the same thing the next day..

its okay if you wont teach me the whole code,i just need an idea..ive been studying vb 2008 express edition myself for 3 months no.

please e-mail me: bien_zales@yahoo.com
THANKS in advance.

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.