PDA

View Full Version : سوال: ساخت فایل DAT



ly.comeng
سه شنبه 20 بهمن 1388, 12:17 عصر
با سلام

من میخوام توی پروژه ام یک دکمه بذارم برای تهیه دیسکت(دیسکت بانک) که فایل ساخته شده باید فرمت DAT باشه.
توی این فایل گزارش 3 تا فیلد میخوام از پایگاه داده ذخیره کنم(مثل شماره حساب،حقوق خالص پرداختی ،تاریخ)
لطفا راهنمایی بفرمایید چطوری میتونم کد رو بنویسم

ممنونم

alimanam
سه شنبه 20 بهمن 1388, 12:32 عصر
با سلام

دوست عزیز آیا نوع اطلاعاتی که می خواین دراین فایل ذخیره بشه با فرمتی خاصی باید باشه آیا باید Encrypt بشه ؟ درکل نوشتن همچین فایلی بسیار آسونه شما با چندین روش میتونین کار کنین . نمونه کد زیر ساده ترین روشه .


' Load the file's contents into the TextBox.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Try
Dim file_name As String = Application.StartupPath() _
& "\text.dat"
Dim stream_reader As New IO.StreamReader(file_name)
Try
txtFileContents.Text = stream_reader.ReadToEnd()
txtFileContents.Select(0, 0)
Finally
stream_reader.Close()
End Try
Catch exc As System.IO.FileNotFoundException
' Ignore this error.
Catch exc As Exception
' Report other errors.
MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Read " & _
"Error")
End Try
End Sub

' Save the current text.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles _
MyBase.Closing
Try
Dim file_name As String = Application.StartupPath() _
& "\text.dat"
Dim stream_writer As New IO.StreamWriter(file_name, _
False)
Try
stream_writer.Write(txtFileContents.Text)
Finally
stream_writer.Close()
End Try
Catch exc As Exception
' Report all errors.
MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Read " & _
"Error")
End Try
End Sub

نمونه کدش رو هم ضمیمه کردم .
منبع : http://www.vb-helper.com/howto_net_read_write_text_file.html

یا علی

Sharif Lotfi
جمعه 23 بهمن 1388, 19:24 عصر
همونطور که دوستمون گفتن براحتی می تونید با فایلهای txt ارتباط بر قرار کنین
یه نمونه کد میذارم اینجا . شما می تونین با کمی تغییر ازش استفاده کنین :

Dim path as string ="C:\test.dat"
Dim fs As FileStream = File.Create(path)
fs.Close()

AllTextInRow = "Name" + vbTab + "Age" + vbTab + "Address" + Environment.NewLine
File.AppendAllText(path, AllTextInRow)
AllTextInRow = String.Format("{0}{1}{2}{1}{3}",myName,vbTab,myAge,myAddress)
File.AppendAllText(path, AllTextInRow)

موفق و سبز باشی

ly.comeng
جمعه 30 بهمن 1388, 19:28 عصر
همونطور که دوستمون گفتن براحتی می تونید با فایلهای txt ارتباط بر قرار کنین
یه نمونه کد میذارم اینجا . شما می تونین با کمی تغییر ازش استفاده کنین :

Dim path as string ="C:\test.dat"
Dim fs As FileStream = File.Create(path)
fs.Close()

AllTextInRow = "Name" + vbTab + "Age" + vbTab + "Address" + Environment.NewLine
File.AppendAllText(path, AllTextInRow)
AllTextInRow = String.Format("{0}{1}{2}{1}{3}",myName,vbTab,myAge,myAddress)
File.AppendAllText(path, AllTextInRow)

موفق و سبز باشی

دوستان ممنونم اما من ا text نميخوام بريزم توي فايل من ميخوام از ديتا بيس مثلا از يك view يا table چند تا فيلد بريزم توي فايل.
؟؟؟