|
Hello,
I am using Vs.Net 2005. In my project i am using SQL 2000 DataBase & it will be on network. I had done connection string to access data from network and in this project i want to save txt file on that system, there SQL database in C:/Data
How i can do this PLZ help me.
Thanks & Regards
Form :-
Vikash Yadav
|
|
|
|
|
Vikash Yadav wrote: How i can do this PLZ help me.
I'm still trying to work out what you want.
Do you want to save the text file on the same computer that has SQL Server installed?
If yes, then you need to create a network share on the target computer. Then to save the file you use the full UNC path name. e.g. \\ServerName\ShareName\FolderName\File.txt
|
|
|
|
|
Thanks For Help
I will try this
Thanks & Regards
Form :-
Vikash Yadav
|
|
|
|
|
Hi, I am getting access denied error.The complete code is here.
It some time showing access denied errorto the file.Is there anything wrong.
Plese Help me. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
add_hit_to_txtfile()
End If
End Sub
Private Sub add_hit_to_txtfile()
Dim url As String = Request.RawUrl
Dim a() As String = url.Split("/")
Dim b() As String = a(a.Length - 1).Split(".aspx")
Dim page_name As String = b(0)
HitCounter(page_name)
End Sub
Public Sub EntryInCurrentDate(ByVal reqPage As String, Optional ByVal subFolder As Integer = 0)
Dim myPath As String = ""
Dim pathLog As String = ""
Dim pathLoc As String = ""
Dim pathZip As String = ""
Select Case subFolder
Case 0
myPath = "Data\DateWiseHit.xml"
Pathlog = "Data\login.txt"
pathLoc = "Data\txtloc.txt"
pathZip = "Data\ZIP_CODES.txt"
Case 1
myPath = "..\Data\DateWiseHit.xml"
Pathlog = "..\Data\login.txt"
pathLoc = "..\Data\txtloc.txt"
pathZip = "..\Data\ZIP_CODES.txt"
End Select
Dim objStreamReader As StreamReader
Dim objStreamWriter As StreamWriter
Dim strInput As String
Dim strOutput As String = ""
Dim check As Integer = 0
Dim i As Integer
Dim strDateNHit() As String
Dim Len As Integer
Dim NoOfHit As Integer = 0
Dim Hit() As String
Dim strLine As String = ""
Dim blnComa As Boolean = False
Dim blnReqPageFound As Boolean = False
Dim blnCurrentDataExist As Boolean = False
Dim blnDataExist As Boolean = False
Dim blnNewLine As Boolean = False
Dim a() As String
If File.Exists(HttpContext.Current.Server.MapPath(myPath)) Then
objStreamReader = File.OpenText(Request.MapPath(myPath))
strInput = objStreamReader.ReadLine
While strInput <> Nothing
blnComa = False
blnDataExist = True
strDateNHit = strInput.Split("|")
If CDate(strDateNHit(0)) = Date.Today Then
blnCurrentDataExist = True
strLine = Date.Today & "|"
Hit = strDateNHit(1).Split(";")
Len = Hit.Length - 1
For i = 0 To Len
a = Hit(i).Split(":")
If a(0).Trim = reqPage.Trim Then
blnReqPageFound = True
NoOfHit = a(1)
NoOfHit = NoOfHit + 1
If blnComa Then
strLine = strLine & ";" & reqPage & ":" & NoOfHit
Else
strLine = strLine & reqPage & ":" & NoOfHit
blnComa = True
End If
Else
If blnComa Then
strLine = strLine & ";" & Hit(i)
Else
strLine = strLine & Hit(i)
blnComa = True
End If
End If
Next
If Not blnReqPageFound Then
If blnComa Then
strLine = strLine & ";" & reqPage & ":" & 1
Else
strLine = strLine & reqPage & ":" & 1
End If
End If
If blnNewLine Then
strOutput = strOutput & vbCrLf & strLine
Else
strOutput = strOutput & strLine
End If
Else
If blnNewLine Then
strOutput = strOutput & vbCrLf & strInput
Else
strOutput = strOutput & strInput
End If
End If
blnNewLine = True
strInput = objStreamReader.ReadLine
End While
If Not blnCurrentDataExist Then
strLine = Date.Today & "|"
strLine = strLine & reqPage & ":" & 1
If blnNewLine Then
strOutput = strOutput & vbCrLf & strLine
Else
strOutput = strOutput & strLine
blnNewLine = True
End If
End If
objStreamReader.Close()
objStreamReader.Dispose()
Else
strLine = Date.Today & "|"
strLine = strLine & reqPage & ":" & 1
strOutput = strLine
End If
objStreamWriter = File.CreateText(Request.MapPath(myPath))
objStreamWriter.WriteLine(strOutput)
objStreamWriter.Close()
objStreamWriter.Dispose()
End Sub
Public Function getCSTdateTime()
Dim strDateTime As String
Dim strReturn As String
Dim strSdateTime As String
Dim a() As String
Dim b() As String
Dim FdateTime As DateTime = DateTime.Now
Dim SdateTime As DateTime = DateTime.Now
strSdateTime = SdateTime.ToString("s")
b = strSdateTime.Split("T")
strSdateTime = b(1)
strDateTime = FdateTime.ToString("F")
a = strDateTime.Split(",")
strReturn = a(0) & " " & a(1) & " " & b(1) & " " & "PST time" & " " & Date.Now.Year
Return strReturn
End Function
Public Function HitCounter(ByVal reqPage As String, Optional ByVal subFolder As Integer = 0)
Dim myPath As String = ""
Select Case subFolder
Case 0
myPath = "Data\HitCounter.xml"
Case 1
myPath = "..\Data\HitCounter.xml"
End Select
Dim strToRead As String = ""
Dim strToWrite As String = ""
Dim i As Integer = 0
Dim hitCount As Integer = 1
Dim check As Integer = 0
Dim objStreamReader As StreamReader
Dim objStreamWriter As StreamWriter
Dim blnReqPageFound As Boolean = False
Dim strReturn As String = "You are visitor # "
EntryInCurrentDate(reqPage, subFolder)
If File.Exists(HttpContext.Current.Server.MapPath(myPath)) Then
objStreamReader = File.OpenText(Request.MapPath(myPath))
strToRead = objStreamReader.ReadLine
Dim a() As String = strToRead.Split(";")
For i = 0 To a.Length - 1
Dim b() As String = a(i).Split(":")
If (b(0) = reqPage) Then
blnReqPageFound = True
hitCount = b(1)
hitCount = hitCount + 1
If (check = 0) Then
strToWrite = reqPage & ":" & hitCount
check = 1
Else
strToWrite = strToWrite & ";" & reqPage & ":" & hitCount
End If
Else
If check = 0 Then
strToWrite = a(i)
check = 1
Else
strToWrite = strToWrite & ";" & a(i)
End If
End If
check = 1
Next
If Not blnReqPageFound Then
If (check = 0) Then
strToWrite = reqPage & ":" & hitCount
check = 1
Else
If strToWrite = "" Then
strToWrite = reqPage & ":" & hitCount
Else
strToWrite = strToWrite & ";" & reqPage & ":" & hitCount
End If
End If
End If
objStreamReader.Close()
objStreamReader.Dispose()
Else
strToWrite = reqPage & ":" & hitCount
End If
objStreamWriter = File.CreateText(Request.MapPath(myPath))
objStreamWriter.WriteLine(strToWrite)
objStreamWriter.Close()
objStreamWriter.Dispose()
strReturn = strReturn & hitCount
Return strReturn
End Function
|
|
|
|
|
Sorry for my bad English. I've designed a form like this
http://img524.imageshack.us/img524/2656/untitled1xj8.jpg[^]
The textbox show the classID and the datagird will display the list of students of this class. Table Student in my database has classID field too, of course ! But I don't display column classID on datagrid. When I click Update button, I want to save all data has been change in datagrid and save the value of classID in the textbox into classID field in Student table. Can anyone help me ?
Thank for reading !
|
|
|
|
|
Hi,
If the user deletes rows or just changes data there shouldn't be any problems, but if they try to add rows, you will get missing key errors. You can try this:
<br />
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click<br />
Dim rw As DataRow<br />
For Each rw In DataSet1.Tables(0).Rows<br />
If IsDBNull(rw.Item("ClassID")) = True Then rw.Item("ClassID") = YourTextBox.Text<br />
Next<br />
DataSet1.AcceptChanges()<br />
End Sub<br />
Hope it works,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
It really work ! Thank you very much. But it still has a problem. I use update method of dataAdapter to update the changings data in datagrid. And when I add your code in, I can't delete round(s) in datagrid. What should I do ?
Here is the code
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
dataConnection.Open()
Dim temp As DataTable
temp = table.GetChanges() 'table is a dataTable which is used for
'datagrid source
If Not temp Is Nothing Then
Try
Dim r As DataRow
For Each r In temp.Rows
If IsDBNull(r.Item("classID")) = True Then
r.Item("classID") = TextboxClassID.Text
End If
Next
dataAdapter.Update(temp)
table.AcceptChanges()
Catch ex As Exception
table.RejectChanges()
dataConnection.Close()
MsgBox(ex.ToString)
End Try
End If
dataConnection.Close()
End Sub
-- modified at 8:34 Monday 5th February, 2007
|
|
|
|
|
As far as I can tell, it should work if you change your code a little bit:
<br />
tam.AcceptChanges() 'try this<br />
table.AcceptChanges() 'or try this, or try to use both lines, but before the update command<br />
dataAdapter.Update(temp)<br />
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I've edited my code as you said but it didn't work. Here is the error message
System.Data.DatarowInaccessibleException: deleted row information cannot be accessed through the row
|
|
|
|
|
Please test this:
<br />
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click<br />
dataConnection.Open()<br />
Dim temp As DataTable<br />
Try<br />
Dim r As DataRow<br />
For Each r In table.Rows<br />
If IsDBNull(r.Item("classID")) = True Then<br />
r.Item("classID") = TextboxClassID.Text<br />
End If<br />
Next<br />
table.AcceptChanges()<br />
temp = table.GetChanges() 'table is a dataTable which is used for datagrid source<br />
If Not temp Is Nothing Then dataAdapter.Update(temp)<br />
Catch ex As Exception<br />
table.RejectChanges()<br />
dataConnection.Close()<br />
MsgBox(ex.ToString)<br />
End Try<br />
End If<br />
dataConnection.Close()<br />
End Sub<br />
If that also doesn't work, I will try to have another look at it tomorrow.
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
It didn't work. Here is the error message
System.Data.DatarowInaccessibleException: deleted row information cannot be accessed through the row
at the line "If IsDBNull(r.Item("classID")) = True Then"
|
|
|
|
|
How about this:
<br />
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click<br />
dataConnection.Open()<br />
Dim temp As DataTable<br />
Try<br />
table.AcceptChanges()<br />
Dim r As DataRow<br />
For Each r In table.Rows<br />
If IsDBNull(r.Item("classID")) = True Then<br />
r.Item("classID") = TextboxClassID.Text<br />
End If<br />
Next<br />
table.AcceptChanges()<br />
temp = table.GetChanges() 'table is a dataTable which is used for datagrid source<br />
If Not temp Is Nothing Then dataAdapter.Update(temp)<br />
Catch ex As Exception<br />
table.RejectChanges()<br />
dataConnection.Close()<br />
MsgBox(ex.ToString)<br />
End Try<br />
End If<br />
dataConnection.Close()<br />
End Sub<br />
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
It didn't work. No error message but when I ran debug, I found this :
temp is nothing
And dataAdapter didn't update anything.
|
|
|
|
|
The problem is that the IsDBNull check can not access rows where the RowState is Deleted (so we tried to call AcceptChanges first, but your update statement needs to know the RowState of each datarow to work, and AcceptChanges sets all RowStates to Unchanged. That's why the code didn't throw any errors, but also didn't update anything, because table.GetChanges() didn't find any changes anymore.
However, if the row was deleted than we don't have to add the ClassID anyway. So let's try the following:
<br />
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click<br />
dataConnection.Open()<br />
Dim temp As DataTable<br />
Try<br />
Dim r As DataRow<br />
For Each r In table.Rows<br />
If r.RowState <> DataRowState.Deleted Then<br />
If IsDBNull(r.Item("classID")) = True Then r.Item("classID") = TextboxClassID.Text<br />
End If<br />
Next<br />
temp = table.GetChanges() 'table is a dataTable which is used for datagrid source<br />
If Not temp Is Nothing Then dataAdapter.Update(temp)<br />
table.AcceptChanges() 'this may not be necessary<br />
Catch ex As Exception<br />
table.RejectChanges()<br />
dataConnection.Close()<br />
MsgBox(ex.ToString)<br />
End Try<br />
End If<br />
dataConnection.Close()<br />
End Sub<br />
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
It worked finally ! And the last question. In dataAdapter I used "select * from student" and I filled them in datatable which names Table. Table is used for datagrid's source. But I don't want to display classID column in datagrid, what should I do ? Thank you very much for your help so far !
|
|
|
|
|
No problem, I am glad to hear it works.
If you want to filter out certain columns from view, you will have to use the Data Grid's TableStyles property (form designer > datagrid's properties > 4th from the bottom usually).
With this property you can put a "mask" between the table and the datagrid. Just add a table to the TableStyle and use its MappingName property to map it to your table.
To the TableStyle table you just created, you add GridColumnStyles (usually 3rd from the bottom). Just add a column here for each column you want to show, and map each column to the appropriate column in your table.
With GridColumnStyles, if you like, you can then also determine column width, alternating row color, etc.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks again ! Could you write commandline like this
dim TableStyle as new datagridTableStyles
etc.
I have read the example in MSDN. But I couldn't write the code.
|
|
|
|
|
It is indeed possible to make these TableStyles, etc, at runtime, but it is just far easier to do it in the designer. For the same reason I have no experience with implementing TableStyles at runtime myself.
If you really must do it that way, I suggest that you experiment a little bit, and if necessary, post an entirely new question on this board. Maybe someone else can help you with it.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I have made it work on my own. But thank you anyway ! I've just read your signature and I think I'm a lucky man. I'm just a university student and I have nothing to pay you . Would you like to make friend with me ? Here is my email cotinhkhongtin@yahoo.com .
|
|
|
|
|
I got new problem here. StudentID is the primary key of the datatable Student. I don't want to display this column on datagrid. When I finish editing a row and click to other row on datagrid, error mesage appears "StudentID is not allowed null". I use a function name CreateKey to create the value of StudentID. I put the function CreateKey on the CurrentCellChanges event but it didn't work. Can you help me ?
-- modified at 10:22 Wednesday 14th February, 2007
|
|
|
|
|
Hi Bircut,
I have a feeling that maybe you need to look at the structure of the application, and not so much at where to place your function. What I mean is this:
Let's say that after you have created your Classroom ID, you want to add students to the classroom.
First you need to create the students in their own table. We can safely assume that this will be done by an administrator, who is allowed to see the Student ID (you don't have to hide it here). So you make a form in which the admin can add, delete and change students (all the students in the entire school). Your CreateKey function can be implemented here somewhere, because you want a unique ID for each student.
Next you can make an 'Add Student' Button and a ComboBox (for example) that you bind to the Students table. From this ComboBox you can then select a student from the Student Table, and add it to the Classroom Table with the Button. Something along the lines of:
<br />
'Button_Click Event:<br />
'Determine correct record from Student table based on Student name (for example)<br />
Dim StudentName as String<br />
StudentName = ComboBox.SelectedItem<br />
SQL_string = "Select * From Students Where Students.StudentName = '" & StudentName & "'"<br />
To the DataGrid that shows the students in the classroom, you then add a TableStyle, and GridColumnStyles only for the columns you want to show.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I undertood your method and I had thought about this before. But my professor didn't agree. I also thought about using autonumber type to make the value. But I tried to use the function CreateKey because the character in StudentID have their meaning, I want to manage them. But I don't have time to think about it anymore. I need to finish this project before March. So I let the Administrator chose the value of StudentID finally. And one more thing, my project didn't mention about Student and Class. I tried to make thing easy to understand and someone could help me. Thanks again !!!
|
|
|
|
|
Sorry Guys/Ladies... this is a really basic question and you will probably scoff and laugh... I haven’t done any coding in 10 years much less any in VB.Net.
My question is related to a form I have built to return values from a directory. I need the box populated with the file names from a given directory and then populate the second combo box with the selected field in the first combo box...
Sorry for such a basic question, but if possible please help??
|
|
|
|
|
System.IO.Directory.GetAllFiles ( from memory ) will return the filenames. You can use an array as a data source for a control.
The combo has a selected index changed event, you can use this to pass data to the second combo.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi All,
Is there a way to display a form kinda frameless (without the blue bar going across the top and sides making is look like a new window and saying form2 on it)
Thanks in advance
Jaidev
|
|
|
|