Repost: Filling DatagraidView based on control values

  • Thread starter Thread starter Materialised
  • Start date Start date
M

Materialised

Hi All

I have been searching the net on this for the last couple of hours to no
avail.

I need to fill a datagridview control based on the values entered in 2 text
boxes.
However I cant for the life of me figure out who to do this.

Here is my SQL statement:
Dim SQLString As String
SQLString = "SELECT Cutter_Num, [Size_ Across], [Size_ Back], Perf FROM
CUTTERS WHERE ([([Size_ Across] < '" & (Val(txtWidth.Text) -
Val(txtTolerance.Text)) & "'"

I don't think I am able to use the VS.net 2005 Query builder to do this. So
could anyone point me in the right direction for what I hope to achieve?

Regards
 
Materialised,

It makes no sense to repost with the same message.

Probably I was not the only one who did not understand what you want to
achieve.

Maybe can yo rephrase your question?

Cor
 
Sorry Cor,

Let me attempt to rephrase.
Basically I have a data grid control on a form. What I wish to do is
populate this control based on the values (2 No.) that a user inputs.
For example, If the user were to enter the values 22 and 76, the data grid
would only be populated with items within that range.

I can do this using the VS.Net 2005 Query build no problem, however I am
having trouble figuring how to do it manually, i.e using a custom SQL
statement with my dataadapter to populate the datagrid.

Hope this clears some issues up with my post.

Regards
Materialised
 
Materialized.

Make next time your SQL string not so complicated to ask a question. What
you ask is in my opinion something as this

Dim SQLString As String
SQLString = "SELECT MyVariables from MyTable WHERE (VariableA = @One OR
VariableA = @Two")

And than manually using directly the SQLDataAdapter and not the new factored
DBprovider

\\\
dim dt as new datatable
dim conn as new SqlClient.SQLConnection("AConnectionsString")
dim da as new SqlClient.SQLDataAdapter(conn,SQLString)
Set the parameters see for that this link
http://www.vb-tips.com/default.aspx?ID=886bba68-8a2f-4b99-8f66-7139b8970071
da.fill(dt)
datagrid1.datasource = dt
///

All typed here so watch typos or whatever. This is very simple, you need a
Try block and as well can you set the parameters more efficient. See
partially this sample for that.

http://www.vb-tips.com/default.aspx?ID=2e452783-527a-402a-b37a-ae802ee71c86

Using this, you can set the fill and the parameterpart in a section where
the user clicks a button to accept the values.

(The try and catch is as well not in the second sample, if you need help for
that when you have tried this, than ask again)

I hope this helps,

Cor
 
Thanks Cor,

I maybe should have stated this first, but I am using a Access database.

Will the principal you outlined also work with that?

Regards
 
Thanks Cor,
I maybe should have stated this first, but I am using a Access database.

Will the principal you outlined also work with that?

Regards
Yes however have than a look at the same parameter sample on our website
with OleDb

Cor
 
Thank you Cor,

I figured it out with your help, and to be honest it was quite simple, so
not only have I solved my issue, I have also learnt something new today.
For anyone else having issues regarding my subject, here is the way I did
it:

Dim SQLString As String
SQLString = "SELECT Cutter_Num, [Size_ Across], [Size_ Back], Perf FROM
CUTTERS WHERE ([Size_ Across] > " & Val(txtWidth.Text) -
Val(txtTolerance.Text) & ") And ([Size_ Back] < " _
& Val(txtLength.Text) + Val(txtTolerance.Text) & ")"
Try
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Z:\Database\cohnan2.MDB;Persist Security Info=False"
Dim adapter As New OleDbDataAdapter(SQLString, conn)
Dim cutt As New DataSet
adapter.Fill(cutt)
DataGridView1.DataSource = cutt.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace, "Error")
End Try

Once again, thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top