Hello Every one
i'm a newbie in vb.net and i am facing a little problem i hope that someone can help me.
i made a little programme that i need at work witch have 15 textbox and in each textbox we will enter
a data that will be saved in an access db. till now i made it throught and everything workjs fine
the problem is that i want to make a button that will save the saved data in the db to a txt file
i found a little code that will open a dialog to chose the path and the name of the txt file but i can't make it to import the data from the db
PS: i need to save the data of each line in the Db to a single line in the txt file without space between the data.
i'm going to show you the code of the edit buttom to see the db info and the code of the botton witch will save the data to txt file and i hope someone can tell me what do i have to do.
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
'check for the selected item in list
If Me.dgvData.Rows.Count > 0 Then
If Me.dgvData.SelectedRows.Count > 0 Then
Dim intStdID As Integer = Me.dgvData.SelectedRows(0).Cells("id").Value
'get data from database followed by student id
'open connection
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
'get data into datatable
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM student " & _
" WHERE stdid=" & intStdID, cnn)
Dim dt As New DataTable
da.Fill(dt)
Me.txtstdID.Text = intStdID
Me.txtStdName.Text = dt.Rows(0).Item("stdname")
Me.cboGender.Text = dt.Rows(0).Item("gender")
Me.txtPhone.Text = dt.Rows(0).Item("phone")
Me.txtAddress.Text = dt.Rows(0).Item("address")
Me.TextBox1.Text = dt.Rows(0).Item("NAS")
Me.TextBox2.Text = dt.Rows(0).Item("MGF")
Me.TextBox3.Text = dt.Rows(0).Item("DF")
Me.TextBox4.Text = dt.Rows(0).Item("DD")
Me.TextBox5.Text = dt.Rows(0).Item("Dfin")
Me.TextBox6.Text = dt.Rows(0).Item("DR")
Me.TextBox7.Text = dt.Rows(0).Item("MHT")
Me.TextBox8.Text = dt.Rows(0).Item("AF")
Me.TextBox10.Text = dt.Rows(0).Item("TTVA")
Me.TextBox9.Text = dt.Rows(0).Item("Timbre")
'
'hide the id to be edited in TAG of txtstdid in case id is changed
Me.txtstdID.Tag = intStdID
'change button add to update
Me.btnAdd.Text = "Update"
'disable button edit
Me.btnEdit.Enabled = False
'close connection
cnn.Close()
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filewriter As StreamWriter
Dim results As DialogResult
Dim SaveFileDialog1 As New SaveFileDialog()
Dim a As String
Dim intStdID As Integer = Me.dgvData.SelectedRows(0).Cells("id").Value
'get data from database followed by student id
'open connection
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
'get data into datatable
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM student " & _
" WHERE stdid=" & intStdID, cnn)
Dim dt As New DataTable
da.Fill(dt)
a = (Me.txtstdID.Text = intStdID & Me.txtStdName.Text = dt.Rows(0).Item("stdname") & Me.cboGender.Text = dt.Rows(0).Item("gender") & Me.txtPhone.Text = dt.Rows(0).Item("phone") & Me.txtAddress.Text = dt.Rows(0).Item("address") & Me.TextBox1.Text = dt.Rows(0).Item("NAS") & Me.TextBox2.Text = dt.Rows(0).Item("MGF") & Me.TextBox3.Text = dt.Rows(0).Item("DF") & Me.TextBox4.Text = dt.Rows(0).Item("DD") & Me.TextBox5.Text = dt.Rows(0).Item("Dfin") & Me.TextBox6.Text = dt.Rows(0).Item("DR") & Me.TextBox7.Text = dt.Rows(0).Item("MHT") & Me.TextBox8.Text = dt.Rows(0).Item("AF") & Me.TextBox10.Text = dt.Rows(0).Item("TTVA") & Me.TextBox9.Text = dt.Rows(0).Item("Timbre"))
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
filewriter = New StreamWriter(SaveFileDialog1.FileName, False)
filewriter.Write(a)
filewriter.Close()
End If
End Sub
i know i may made a stupid mistake the thing is that i have no idea on coding with vb.net i just looked for random codes and tryed to modifie them to have what i need.