3 Replies - 2439 Views - Last Post: 22 June 2009 - 08:11 AM Rate Topic: -----

#1 wongth7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 16-June 09

how to insert sql statement in array (vb 2005)?

Posted 22 June 2009 - 01:46 AM

hi guys, im not sure how to explain my problem and what are the ways to solve it but i will try my best to explain what i'm trying to do here

- in my database, there's 2 table....Log, Application

Attached Image

Attached Image

- im trying to construct a sentence for my log, something like..

(eg: Apply Annual Leave from Monday to Friday)

-words in bold are to be retrieved from the Application table (database)



here's my vb code (im not sure whether i should be using array or not...and im not so sure how to use it too )

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click


con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; data source= H:\Project\user.mdb"
con.Open()
sql = "SELECT * From Log"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "LogList")
con.Close()
maxrows = ds.Tables("LogList").Rows.Count

Dim sqlstr1 As String
Dim sqlstr2 As String
Dim sqlstr3 As String

sqlstr1 = "select Type from Application where ID ='" & txtcancel.Text & "'"
sqlstr2 = "select Dayfrom from Application where ID ='" & txtcancel.Text & "'"
sqlstr3 = "select Dayto from Application where ID ='" & txtcancel.Text & "'"


Try
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("LogList").NewRow()


dsNewRow.Item("Sentence") = "Apply " & sqlstr1 & "from" & sqlstr2 & "to" & sqlstr3


ds.Tables("LogList").Rows.Add(dsNewRow)
da.Update(ds, "LogList")
MessageBox.Show("Data insert into log", "Confirm")


End If
Catch ex As Exception
MessageBox.Show("Error in one of the fields", "Error")

End Try

End Sub


but when i view my Log..something like this appear

Attached Image

-how do i let the array know that the statement is an sql statement, not text??

-or is there any other way to do it??

-can someone provide me a sample code or something??

thanks :)

This post has been edited by wongth7: 22 June 2009 - 01:47 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how to insert sql statement in array (vb 2005)?

#2 CamoDeveloper  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 20
  • View blog
  • Posts: 250
  • Joined: 12-June 09

Re: how to insert sql statement in array (vb 2005)?

Posted 22 June 2009 - 05:46 AM

Looks like you're not even selecting the data from the code you've provided. So it's just printing out the string you assigned it.

~Camo
Was This Post Helpful? 0
  • +
  • -

#3 wongth7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 16-June 09

Re: how to insert sql statement in array (vb 2005)?

Posted 22 June 2009 - 06:03 AM

View PostCamoDeveloper, on 22 Jun, 2009 - 04:46 AM, said:

Looks like you're not even selecting the data from the code you've provided. So it's just printing out the string you assigned it.

~Camo


so any idea how to solve it ?
Was This Post Helpful? 0
  • +
  • -

#4 CamoDeveloper  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 20
  • View blog
  • Posts: 250
  • Joined: 12-June 09

Re: how to insert sql statement in array (vb 2005)?

Posted 22 June 2009 - 08:11 AM

Do the same thing you did with the "SELECT * FROM Log" but with those three querys.

~Camo
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1