fsuedu
asked on
Visual Studio Visual Basic Form load from sql database
I have the following code
Private Sub SettlementStatment_Load(By Val sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SettlementTableAdapter. Fill(Me.Ni ghtAuditDa taSet.Sett lement)
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------'
Dim row As DataRow = NightAuditDataSet.Tables(0 ).Rows(Nig htAuditDat aSet.Table s(0).Rows. Count - 1)
MessageBox.Show(row(0).ToS tring())
Me.Sitetxt.Text = 2
End Sub
The fields are set up in the databindings properties at form[Desing]
but when you load the form the fields do not populate.
Even though the MessageBox.Show(row(0).ToS tring())
Shows the last record number.
First time doing this --can you tell me the code for the sub
if I give you this
Server=FESSQL;Database=Nig htAudit;Tr usted_Conn ection=yes ;"
Table Name ----Settlement
Tried to make work -but had no luck
I'm I missing something relating to this:
myConnection = New SqlConnection(ConnStr)
sql = "select * from tblSubCategories"
da = New SqlDataAdapter(sql, myConnection)
da.Fill(ds, "tblSubCategories")
dg.DataSource = ds.Tables(0)
JK
Private Sub SettlementStatment_Load(By
Me.SettlementTableAdapter.
'-------------------------
Dim row As DataRow = NightAuditDataSet.Tables(0
MessageBox.Show(row(0).ToS
Me.Sitetxt.Text = 2
End Sub
The fields are set up in the databindings properties at form[Desing]
but when you load the form the fields do not populate.
Even though the MessageBox.Show(row(0).ToS
Shows the last record number.
First time doing this --can you tell me the code for the sub
if I give you this
Server=FESSQL;Database=Nig
Table Name ----Settlement
Tried to make work -but had no luck
I'm I missing something relating to this:
myConnection = New SqlConnection(ConnStr)
sql = "select * from tblSubCategories"
da = New SqlDataAdapter(sql, myConnection)
da.Fill(ds, "tblSubCategories")
dg.DataSource = ds.Tables(0)
JK
Your dataset/datatable is obviously being filled with something or you wouldn't get the last record number being reported. So there seems to be something wrong with the bindings.
You say "The fields are set up in the databindings properties at form[Desing]". How was that done? Did you drag stuff from the DataSource window onto the form? Or did you drag controls from the ToolBox onto the form and then set the databindings by clicking the little buttons in the top right corner?
And can you please clarify the last bit of your post? That seems to be dealing with a different table - "tblSubCategories" - rather than a table called "Settlement" which is (a) what your description "Table Name ----Settlement" refers to and (b) successfully brought over by the tableadapter. Is the dg you refer to in that one of the controls for which "The fields are set up in the databindings properties at form[Desing]"?
Roger
You say "The fields are set up in the databindings properties at form[Desing]". How was that done? Did you drag stuff from the DataSource window onto the form? Or did you drag controls from the ToolBox onto the form and then set the databindings by clicking the little buttons in the top right corner?
And can you please clarify the last bit of your post? That seems to be dealing with a different table - "tblSubCategories" - rather than a table called "Settlement" which is (a) what your description "Table Name ----Settlement" refers to and (b) successfully brought over by the tableadapter. Is the dg you refer to in that one of the controls for which "The fields are set up in the databindings properties at form[Desing]"?
Roger
ASKER
Hello Sancler
I dragged controls from the ToolBox onto the form and then set the databindings by right clicking -go to properties-Data-(DataBindi ngs)-Text- Then Select from the datasource the Appropriate sql field that matches the txt field?
No the last part was just an exampe -of code that I thought I might be missing
Thanks for your help
I dragged controls from the ToolBox onto the form and then set the databindings by right clicking -go to properties-Data-(DataBindi
No the last part was just an exampe -of code that I thought I might be missing
Thanks for your help
What does it say opposite the Text heading, under the DataBindings Heading, in the TextBox's Properties window? If, as is quite likely, it refers to <someName>BindingSource what does it say under the headings DataSource and DataMember in the Properties window for that? I would expect it to be NightAuditDataSet for the former and Settlement for the latter.
Roger
Roger
ASKER
For exampe it say SettlementBindingSource - PreviouAdvDepositstxt for the properties for txtbox PreviouAdvDepositstxtText
Lost on where to go for the last part what does it say under the headings DataSource and DataMember in the Properties window for that?
Under the form[Design]
I have NightAuditDataSet ,SettlementBindingSource,S ettlementT ableAdapte r
if I look at SettlementBindingSource properties in DataSource it has NightAuditDataSet
if that help?
Jk
Lost on where to go for the last part what does it say under the headings DataSource and DataMember in the Properties window for that?
Under the form[Design]
I have NightAuditDataSet ,SettlementBindingSource,S
if I look at SettlementBindingSource properties in DataSource it has NightAuditDataSet
if that help?
Jk
SettlementBindingSource should also have a property DataMember. It's pretty certain, given that the BindingSource is called SETTLEMENTBindingSource that that property will be Settlement. If so, the databindings look like they should work.
But if you can confirm that, it will close down one avenue of enquiry.
Can you try please changing the code that gets the number for your MsgBox to this
Dim row As DataRow = NightAuditDataSet.Tables(" Settlement ").Rows(Ni ghtAuditDa taSet.Tabl es("Settle ment").Row s.Count - 1)
MessageBox.Show(row(0).ToS tring())
and see if it's still giving the result you expect?
Roger
But if you can confirm that, it will close down one avenue of enquiry.
Can you try please changing the code that gets the number for your MsgBox to this
Dim row As DataRow = NightAuditDataSet.Tables("
MessageBox.Show(row(0).ToS
and see if it's still giving the result you expect?
Roger
ASKER
Good Morning
get this error message: Cannot bind to the property or column DateStamptxt on the DataSource.
Parameter name: dataMember
get this error message: Cannot bind to the property or column DateStamptxt on the DataSource.
Parameter name: dataMember
It's very difficult debugging things like this at a distance. There's so many bits and pieces now scattered - by VB.NET 2005 - through so many files. What I suggest you do is zip up the whole project and upload the .zip file here
http://www.ee-stuff.com/
then post the URL that you are given back in this thread. That way, I can look at it as a whole rather than having to ask detailed questions. If you want to remove any sensitive stuff - e.g. passwords in Connection Strings - before you do so, that will be OK. Just replace them with *****, so I can recognise what's for real.
Roger
http://www.ee-stuff.com/
then post the URL that you are given back in this thread. That way, I can look at it as a whole rather than having to ask detailed questions. If you want to remove any sensitive stuff - e.g. passwords in Connection Strings - before you do so, that will be OK. Just replace them with *****, so I can recognise what's for real.
Roger
ASKER
Thanks here is the direct link
https://filedb.experts-exchange.com/incoming/ee-stuff/2889-NightAudit.zip
https://filedb.experts-exchange.com/incoming/ee-stuff/2889-NightAudit.zip
The good news is that I can find nothing wrong. The bad news is that that gets you no nearer to solving your problem.
Although I have done a pretty through review of the code, I cannot actually run it to test without data. I did dummy up a form and some data just to test out the settings on the DateStamptxt control but, as I expected from the code, the binding worked OK on that.
Originally, as I understood things, the form was loading OK and your message box was showing a value that confirmed that the data was loading, but all the controls were left blank. With the error reported in your latest post, I would not even expect the form to load. That error would occur on this line
Me.DateStamptxt.DataBindin gs.Add(New System.Windows.Forms.Bindi ng("Text", Me.SettlementBindingSource , "DateStamptxt", True))
in the InitializeComponent Sub. Am I right about that? If so, what changes did you make between the original position and that which you are now reporting?
Roger
Although I have done a pretty through review of the code, I cannot actually run it to test without data. I did dummy up a form and some data just to test out the settings on the DateStamptxt control but, as I expected from the code, the binding worked OK on that.
Originally, as I understood things, the form was loading OK and your message box was showing a value that confirmed that the data was loading, but all the controls were left blank. With the error reported in your latest post, I would not even expect the form to load. That error would occur on this line
Me.DateStamptxt.DataBindin
in the InitializeComponent Sub. Am I right about that? If so, what changes did you make between the original position and that which you are now reporting?
Roger
ASKER
You might want to kill me I just relized it is pulling the data
from the SQL Table--but it is the first row instead of the last?
It is going off this
Dim row As DataRow = NightAuditDataSet.Tables(0 ).Rows(Nig htAuditDat aSet.Table s(0).Rows. Count - 1)
MessageBox.Show(row(0).ToS tring())
Any Ideas
from the SQL Table--but it is the first row instead of the last?
It is going off this
Dim row As DataRow = NightAuditDataSet.Tables(0
MessageBox.Show(row(0).ToS
Any Ideas
ASKER
Its pulling off Primary Key 91 which is the first record now.
Put should be pulling off record primary key 98
but the message box says 98
Does that make sense?
Put should be pulling off record primary key 98
but the message box says 98
Does that make sense?
When your form loads, the controls will display the data from the first record. Your message box is - specifically - pulling its data from the last. To move between the various records you will need some navigation mechanism, and I don't see any. Just to check, stick a button on your form with this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SettlementBindingSource.Po sition += 1
End Sub
and click it. The controls should then update to reflect different records.
Roger
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SettlementBindingSource.Po
End Sub
and click it. The controls should then update to reflect different records.
Roger
ASKER
Yeap it worked the recordes changed as I hit the button until the last recored.
Is thier a way to make it the last record when it loads?
Is thier a way to make it the last record when it loads?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all your help
If you want I can email it to you.