Question how to put inputed data into a datatable?

Pedro

Member
Joined
Nov 7, 2009
Messages
5
Programming Experience
Beginner
Hello, I need to put the results of a certain calculation on a datatable, so i can see it on a datagrid, and then save it to a new table on a database, and i'm not being succesful..
I've made the contrary with no problem, i've got data from a table onj a database and populated a datatable and a datagrid with it, but having a datatable populated by data that i input is not working..is it not possible?
would someone please help me understand it?
Thanks in advance,
Pedro
 
Well, here it goes..

The problem is on the "SELECT CASE" , where i want to perform a calculation, put the results on the items of "dtCurrListagem", which should be a row of dtList datatable, view it on the datagrid and eventualy save a table on the database with it(this part is not yet writen on code)
hope you can enligth me..
Thanks


CODE

Imports System.Data
Imports System.Data.OleDb
Imports System.Math

Public Class CalcEixo






Private Sub Calcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calcular.Click

Dim ObraDataSet As New DataSet()
Dim drCurr As DataRow
Dim strSQL As String
Dim strList As String
Dim Tipo As String = ""
Dim Pkcurr As Double
Dim Pkini As Double
Dim Pkfin As Double
Dim Desenvolvimento As Double
Dim L As Double
Dim Rumo As Double
Dim P_ini As Double
Dim M_ini As Double
Dim X As Double
Dim y As Double
Dim Dy As Double
Dim Dx As Double
Dim Ang_imp As Double
Dim Dist_imp As Double
Dim Az As Double
Dim Rumo_imp As Double
Dim Raio As Double
Dim pk_n As Double
Dim pk_f As Double
Dim ligacao As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\obra.mdb;"
Dim linha As Integer = 0



Dim odaDiretriz As New OleDb.OleDbDataAdapter
Dim odaListagem As New OleDb.OleDbDataAdapter
Dim dtDiretriz As New DataTable
ObraDataSet.Tables.Add(dtDiretriz)
Dim dtList As New DataTable()
ObraDataSet.Tables.Add(dtList)
Dim CN As New OleDb.OleDbConnection(ligacao)


Dim drCurrListagem As DataRow
pk_n = CDbl(Me.TextBox1.Text)
pk_f = CDbl(Me.TextBox2.Text)
Dim Intervalo As Double = CDbl(Me.TextBox3.Text)
Pkcurr = pk_n

Dim cont1 As Integer = 0
Dim cont As Integer = 0


strSQL = "Select * From Diretriz" ' Where Pk_ini <= Pkcurr And Pk_fin > Pkcurr"
CN.Open()
odaDiretriz = New OleDb.OleDbDataAdapter(strSQL, CN)
CN.Close()

odaDiretriz.Fill(dtDiretriz)
DataGridView1.DataSource = dtDiretriz

Do

Try

drCurr = dtDiretriz.Rows(linha)
Pkini = CDbl(drCurr.Item(0))
Pkfin = CDbl(drCurr.Item(1))
M_ini = CDbl(drCurr.Item(2))
P_ini = CDbl(drCurr.Item(3))
Rumo = CDbl(drCurr.Item(4))
Desenvolvimento = CDbl(drCurr.Item(5))
Tipo = drCurr.Item(6).ToString
Raio = CDbl(drCurr.Item(7))



Catch oexpData As OleDb.OleDbException
MsgBox(oexpData.Message)
Catch osqlData As System.IndexOutOfRangeException

MsgBox("Fora do Projecto, Oh palhaço!!")

End Try



drCurrListagem = dtList.NewRow()

Select Case Tipo

Case "R"
MsgBox("Entrei no select case")
Do While Pkcurr < pk_f
Try


L = Pkcurr - Pkini
Dx = RetaCalcX(L, Rumo)
Dy = RetaCalcY(L, Rumo)
X = Dx + M_ini
y = Dy + P_ini





drCurrListagem("Pk") = Pkcurr
drCurrListagem("M") = X
drCurrListagem("P") = y
drCurrListagem("Rumo") = Rumo


dtList.Rows.Add(drCurrListagem)

MsgBox("Indice da linha=" & dtDiretriz.Rows.IndexOf(drCurr).ToString & "Pkini=" & Pkini & "Pkcurr=" & Pkcurr & "L=" & L & "Pk_f=" & pk_f & "pkfinal=" & Pkfin)

Catch oexpData As OleDb.OleDbException
MsgBox(oexpData.Message)
Catch osqlData As System.IndexOutOfRangeException

MsgBox(osqlData.Message)
Catch ex As Exception

End Try
Pkcurr += Intervalo
If Pkcurr > Pkfin Then

Exit Do
End If
linha += 1

Loop

Case "C"
MsgBox("Entrei no select case")
Do While Pkcurr < pk_f
Try


L = Pkcurr - Pkini
Ang_imp = L / (2 * Raio)
Dist_imp = CDbl(2 * (Sin(Ang_imp) * Raio))
Az = CDbl(Rumo + L / Raio * 200 / 3.141592654)
Rumo_imp = Rumo + CDbl((L / (2 * Raio)) * 200 / 3.141592654)

Dx = RetaCalcX(Dist_imp, Rumo_imp)
Dy = RetaCalcY(Dist_imp, Rumo_imp)
X = Dx + M_ini
y = Dy + P_ini
If Az > 400 Then
Az -= 400
End If





drCurrListagem("Pk") = Pkcurr
drCurrListagem("M") = X
drCurrListagem("P") = y
drCurrListagem("Rumo") = Az


dtList.Rows.Add(drCurrListagem)
MsgBox("Indice da linha=" & dtDiretriz.Rows.IndexOf(drCurr).ToString & "Pkini=" & Pkini & "Pkcurr=" & Pkcurr & "L=" & L & "Pk_f=" & pk_f & "pkfinal=" & Pkfin)
Catch oexpData As OleDb.OleDbException
MsgBox(oexpData.Message)
Catch osqlData As System.IndexOutOfRangeException

MsgBox(osqlData.Message)

End Try
Pkcurr += Intervalo
If Pkcurr > Pkfin Then

Exit Do
End If
linha += 1

Loop

Case "CL"
MsgBox("Entrei no select case")

Do While Pkcurr < pk_f
Try
Dim S As Double
Dim TG As Double
Dim Dx_cl As Double
Dim Dy_cl As Double
L = Pkcurr - Pkini
S = L ^ 2 / (2 * Raio * Desenvolvimento)
Dx_cl = CalcClx(L, S)
Dy_cl = CalcClY(L, S)

Ang_imp = Tan(Dy_cl / Dx_cl)
Rumo_imp = Rumo + (Ang_imp * 200 / 3.141592654)

Dist_imp = Sqrt(Dx_cl ^ 2 + Dy_cl ^ 2)
TG = Rumo + S * 200 / 3.141592654
If TG > 400 Then
TG -= 400
End If
Dx = RetaCalcX(Dist_imp, Rumo_imp)
Dy = RetaCalcY(Dist_imp, Rumo_imp)
X = Dx + M_ini
y = Dy + P_ini

MsgBox("Indice da linha=" & dtDiretriz.Rows.IndexOf(drCurr).ToString) ' & "Pkini=" & Pkini & "Pkcurr=" & Pkcurr & "L=" & L & "Pk_f=" & pk_f & "pkfinal=" & Pkfin)



drCurrListagem("Pk") = Pkcurr
drCurrListagem("M") = X
drCurrListagem("P") = y
drCurrListagem("Rumo") = TG



dtList.Rows.Add(drCurrListagem)

Catch oexpData As OleDb.OleDbException
MsgBox(oexpData.Message)
Catch osqlData As System.IndexOutOfRangeException

MsgBox(osqlData.Message)

End Try
Pkcurr += Intervalo
If Pkcurr > Pkfin Then

Exit Do
End If
linha += 1

Loop


Case "CLS"
Do While Pkcurr < pk_f
Try
Dim S As Double
Dim TG As Double
Dim Dx_cl As Double
Dim Dy_cl As Double


L = Pkcurr - Pkfin
S = L ^ 2 / (2 * Raio * Desenvolvimento)
Dx_cl = CalcClx(L, S)
Dy_cl = CalcClY(L, S)

Ang_imp = Tan(Dy_cl / Dx_cl)
Rumo_imp = Rumo + (Ang_imp * 200 / 3.141592654)

Dist_imp = Sqrt(Dx_cl ^ 2 + Dy_cl ^ 2)
TG = Rumo + S * 200 / 3.141592654 + 200
If TG > 400 Then
TG -= 400
End If
Dx = RetaCalcX(Dist_imp, Rumo_imp)
Dy = RetaCalcY(Dist_imp, Rumo_imp)
X = Dx + M_ini
y = Dy + P_ini

MsgBox("Indice da linha=" & dtDiretriz.Rows.IndexOf(drCurr).ToString) ' & "Pkini=" & Pkini & "Pkcurr=" & Pkcurr & "L=" & L & "Pk_f=" & pk_f & "pkfinal=" & Pkfin)




drCurrListagem("Pk") = Pkcurr
drCurrListagem("M") = X
drCurrListagem("P") = y
drCurrListagem("Rumo") = TG



dtList.Rows.Add(drCurrListagem)

Catch oexpData As OleDb.OleDbException
MsgBox(oexpData.Message)
Catch osqlData As System.IndexOutOfRangeException

MsgBox(osqlData.Message)

End Try
Pkcurr += Intervalo
If Pkcurr > Pkfin Then

Exit Do
End If
linha += 1

Loop

End Select

Loop While Pkcurr < pk_f


DataGridView1.DataSource = dtList



End Sub
End Class

/ CODE
 
Back
Top