Jump to content
Xtreme .Net Talk

noccy

Members
  • Posts

    13
  • Joined

  • Last visited

Everything posted by noccy

  1. Yes, it seems to be a problem with upper and lower... "Å" ToLower returns "Å"... I will try your suggestions as soon as I am back at work... Thanks :)
  2. Hi! I am trying to highlight the search query in a gridview like this: 'foo is the gridview 'strQuery is the search string Dim itm As Object Dim cel As TableCell Dim iHit As Integer Dim strOriginal As String Dim strStart As String If Len(strQuery) > 0 Then For Each itm In foo.Rows For Each cel In itm.Cells If cel.Text.ToLower.Contains(strQuery.ToLower) And cel.Text <> " " Then strStart = "" strOriginal = cel.Text iHit = InStr(strOriginal.ToLower, strQuery.ToLower) If iHit > 1 Then strStart = Left(strOriginal, iHit - 1) End If cel.Text = strStart & "<span style=color:red;background-color:Lime;font-weight:bold>" & Mid(strOriginal, iHit, Len(strQuery)) & "</span>" cel.Text = cel.Text & Right(strOriginal, Len(strOriginal) - (iHit + Len(strQuery)) + 1) End If Next Next End If This works like charm, but if the search string contains any special charachters like the norwegian æ, ø and å, it wont work.... Any ideas? noccy
  3. Hi! I am new to working with xml files, and need to know if I am on the right track... The file is supposed to show the schema of a database: <?xml version="1.0" encoding="utf-8" ?> - <Schema> - <Tables> - <Table Name="Categories"> - <Fields> <Field>Description</Field> </Fields> </Table> - <Table Name="Customers"> - <Fields> <Field>CompanyName</Field> <Field>ContactName</Field> <Field>ContactTitle</Field> </Fields> </Table> - <Table Name="Employees"> - <Fields> <Field>Country</Field> <Field>EmployeeID</Field> <Field>Extension</Field> <Field>FirstName</Field> <Field>HireDate</Field> </Fields> </Table> </Tables> </Schema> thanks noccy
  4. Hi! I am trying to find a way to save a MailMessage sa a .msg file. I create the message like this: Dim msg as new System.Net.Mail.MailMessage Dim att As New system.Net.Mail.Attachment("c:\test.txt") msg.Attachments.Add(att) Does anyone kow if it is possible to save the MailMessage object as a .msg file? noccy
  5. Hi! I am trying to to SQL updates with an access database. One of the fields is a Date/Time field, and the problem occurs when I do n ot want to insert a date. Now I have: Dim strDate as String = Format(myDate, "yyyy-MM-dd HH:mm:ss") Dim strSQL as String = "Update myTable SET date1 ='" & strDate & "' WHERE..." This works fine as long as I have a date to insert... I have tried stuff like... Update myTable SET date1 ='" & IIF(strDate="", "Null", strDate) & "' ...but I can't make it work... Does anyone know how to update datetimefields with null values? noccy
  6. That helps :) Thanks
  7. Hi! I use this code to export the contents og a gridview to MS Excel: Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") Response.Charset = "" ' If you want the option to open the Excel file without saving than ' comment out the line below ' Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls" Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter() Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite) GVInsert.RenderControl(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub This works fine, but my norwegian lettes, æ, ø and å is messed up... I guess i might have something to do with the charset, but i don't know what... noccy
  8. Hi! Are you closing your connection properly when used for login etc?
  9. Hi! I am currently upgrading a VB6 application to .NET, and I have some problems with a function that moves data from a text file into a SQL-server database. With the "old" application I used Access, and ADO, and now I want to use SQL-server and ADO.NET. I have tried different solutions with parameterized queries while looping through the text file, but its just to slow... 15 000 lines takes about 90 seconds to import, which is at least 80 seconds more than my "old" solution. Has anyone god ideas on how to make the import as fast as possible? Here is my VB6 code (that spent 5 seconds on the 15 000 lines) Dim strFileToOpen As String Dim i As Long Dim strLine As String Dim varFields As Variant Dim con As New ADODB.Connection Dim rs As New ADODB.Recordset strFileToOpen = "c:\test.txt" con.ConnectionString = "c:\test.mdb" con.Provider = "Microsoft.Jet.OLEDB.4.0" con.Open rs.Open "SELECT * from tblMytable", con, adOpenStatic, adLockOptimistic i = FreeFile Open strFileToOpen For Input As #i 'Line Input #i, strLine Do While Not EOF(i) Line Input #i, strLine varFields = Split(strLine, ";") With rs .AddNew !Field1 = varFields(0) !Field2 = varFields(1) !Field3 = varFields(2) !Field4 = varFields(3) !Field5 = varFields(4) !Field6 = varFields(5) !Field7 = varFields(6) !Field8 = varFields(7) !Field9 = varFields(8) !Field10 = varFields(9) !Field11 = varFields(10) !Field12 = varFields(11) !Field13 = varFields(12) .Update End With Loop Close #i MsgBox "File was imported" Thanks in advance noccy
  10. Hello! Could you help me on how to acheive this? noccy
  11. Hello! I am currently using this function to input data in a SQL-server database: Public Function ImportTxt(ByVal strDato As String, ByVal strKlokkeslett As String, ByVal strFraNummer As String, ByVal strFraBruker As String, ByVal strTilNummer As String, ByVal strTilBruker As String, ByVal strType As String, ByVal strVarighet As String, ByVal strRetning As String, ByVal strLand As String, ByVal strCelle As String, ByVal strBasestasjon As String, ByVal strIMEI As String, ByVal strKildefil As String, ByVal strDataType As String) As Integer Dim cnn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=PC60380\VSDOTNET; Initial Catalog=**********;user id=****;password=*******") Dim cmd As New SqlClient.SqlCommand() cnn.Open() cmd.Connection = cnn cmd.CommandText = "INSERT INTO tblData " cmd.CommandText = cmd.CommandText & "(Dato, Klokkeslett, FraNummer, FraBruker, TilNummer, TilBruker, AnropType, Varighet, Retning, Land, Celle, Basestasjon, IMEI, Kildefil, DataType)" cmd.CommandText = cmd.CommandText & " VALUES(@Dato, @Klokkeslett, @FraNummer, @FraBruker, @TilNummer, @TilBruker, @AnropType, @Varighet, @Retning, @Land, @Celle, @Basestasjon, @IMEI, @Kildefil, @DataType)" cmd.Parameters.Add("@Dato", SqlDbType.DateTime) cmd.Parameters.Add("@Klokkeslett", SqlDbType.DateTime) cmd.Parameters.Add("@FraNummer", SqlDbType.VarChar, 25) cmd.Parameters.Add("@FraBruker", SqlDbType.VarChar, 200) cmd.Parameters.Add("@TilNummer", SqlDbType.VarChar, 25) cmd.Parameters.Add("@TilBruker", SqlDbType.VarChar, 200) cmd.Parameters.Add("@AnropType", SqlDbType.VarChar, 60) cmd.Parameters.Add("@Varighet", SqlDbType.VarChar, 10) cmd.Parameters.Add("@Retning", SqlDbType.VarChar, 10) cmd.Parameters.Add("@Land", SqlDbType.VarChar, 5) cmd.Parameters.Add("@Celle", SqlDbType.VarChar, 6) cmd.Parameters.Add("@Basestasjon", SqlDbType.VarChar, 100) cmd.Parameters.Add("@IMEI", SqlDbType.VarChar, 20) cmd.Parameters.Add("@Kildefil", SqlDbType.VarChar, 50) cmd.Parameters.Add("@DataType", SqlDbType.VarChar, 20) cmd.Parameters("@Dato").Value = strDato cmd.Parameters("@Klokkeslett").Value = strKlokkeslett cmd.Parameters("@FraNummer").Value = strFraNummer cmd.Parameters("@FraBruker").Value = strFraBruker cmd.Parameters("@TilNummer").Value = strTilNummer cmd.Parameters("@TilBruker").Value = strTilBruker cmd.Parameters("@AnropType").Value = strType cmd.Parameters("@Varighet").Value = strVarighet cmd.Parameters("@Retning").Value = strRetning cmd.Parameters("@Land").Value = strLand cmd.Parameters("@Celle").Value = strCelle cmd.Parameters("@Basestasjon").Value = strBasestasjon cmd.Parameters("@IMEI").Value = strIMEI cmd.Parameters("@Kildefil").Value = strKildefil cmd.Parameters("@DataType").Value = strDatatype cmd.ExecuteNonQuery() cnn.Close() End Function I run this function while looping through a text file, so the function might run 100k times... For small amounts of data the function performes well, but when the number og records to be inserted increases the performance is poor. I am thinking that inserting into a dataset, and then update the db with the dataset would be a faster method, but I have not done that before, and really don't know how to do it... Can anyone tell med how to do this, or if there are other prefered metods? Any help is appreciated noccy
  12. Thank you, I see how to do it now using that method. What if the number of records is 100k or more. Would using a parameterized query improve performance, and if so how would I set it up? Edit: I have run a test with 25000 records, and my old ADO method used about 3 seconds to import the file, while the ADO.NET with a loop and INSERT INTO commands used about 45 seconds... Would a paramterized query be the best solution or are there other methods that are as/more efficient? Here is the code I used to test: Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click Dim cnn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=PC60380\VSDOTNET; Initial Catalog=****_;user id=******;password=*******") Dim cmd As New SqlClient.SqlCommand() Dim fs As New System.IO.FileStream(Me.txtFilePath.Text, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read) Dim sr As New System.IO.StreamReader(fs) Dim strLine As String Dim strField() As String Dim strF1 As String Dim strF2 As String cnn.Open() cmd.Connection = cnn Do While sr.EndOfStream = False strLine = sr.ReadLine() strField = Split(strLine, ";") strF1 = strField(0) If strField.Length > 1 Then strF2 = strField(1) Else strF2 = "" End If cmd.CommandText = "INSERT INTO tblBrukere(Nummer,Bruker) VALUES ('" & strF1 & "', '" & strF2 & "')" cmd.ExecuteNonQuery() Loop cnn.Close() sr.Close() MsgBox("OK!") End Sub noccy
  13. Hello! I have a vb6 application running with the following code to import a text file to an Access database. Can anyone tell me how to do the same import using ADO.NET? Private Sub import() Dim strFileToOpen As String Dim i As Long Dim strLine As String Dim varFields As Variant Dim con As New ADODB.Connection Dim rs As New ADODB.Recordset strFileToOpen = "c:\test.txt" con.ConnectionString = "c:\test.mdb" con.Provider = "Microsoft.Jet.OLEDB.4.0" con.Open rs.Open "SELECT * from tblMytable", con, adOpenStatic, adLockOptimistic i = FreeFile Open strFileToOpen For Input As #i 'Line Input #i, strLine Do While Not EOF(i) Line Input #i, strLine varFields = Split(strLine, ";") With rs .AddNew !Field1 = varFields(0) !Field2 = varFields(1) !Field3 = varFields(2) !Field4 = varFields(3) !Field5 = varFields(4) !Field6 = varFields(5) !Field7 = varFields(6) !Field8 = varFields(7) !Field9 = varFields(8) !Field10 = varFields(9) !Field11 = varFields(10) !Field12 = varFields(11) !Field13 = varFields(12) .Update End With Loop Close #i MsgBox "File was imported" End Sub
×
×
  • Create New...