|
As per Your 2nd point, am i passing the dates and datetimes as SQL paramters in my following select command:
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] = '" + dateofj + "'GROUP BY [Client ID]", con)
|
|
|
|
|
No you are not. You are passing a string, and C# is implicitly calling dateofj.ToString() to perform a string concatenation afterwards; that is where the regional settings are sneaking in your code.
You need this[^] to be safe.
|
|
|
|
|
Instead of
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] = '" + dateofj + "'GROUP BY [Client ID]", con)
use:
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] = @DateOfJ GROUP BY [Client ID]", con)
cmd.Parameters.AddWithValue(@DateOfJ, YourDateValueHere)
|
|
|
|
|
Hey guys I am currently making a program that will allow a user to open/create a file and then after adding data to the file
he/she can search the file by Record number. But i am trying to come up with a If statement that will test if the Recordnumber
the user enters is NOT FOUND then display an error message, I have written this so far, but it doesn't like how I am
trying to convert a string to a double. THANKS for the HELP
Module modulePersonRec
Structure personRecord
<VBFixedString(7)> Public RecordNum As String
<VBFixedString(9)> Public SS As String
<VBFixedString(40)> Public name As String
<VBFixedString(10)> Public Tele As String
<VBFixedString(2)> Public lineBreak As String
End Structure
Public datafile As String
Public person As personRecord
Public position As Long
Public lastrec As Long
Public RecLength As Long
Public LastRecord As Integer
Public filelength As Long
Public indexSS(100) As String
Public indexKey(100) As Long
End Module
Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
'*****************************************************88
'THIS SUBROUTINE WILL ALLOW THE USER TO FIND A RECORD
'BASED ON THE RECORD NUMBER THE USER ENTERS INTO
'A REQUIRED FIELD. IF THE RECORD IS FOUND THEN
'THE CORRESPONDING DATA WILL BE DISPLAYED
'****************************************************
FileGet(1, person, Val(txtRecNum.Text))
If person.RecordNum <> Val(txtRecNum.Text) Then
MessageBox.Show("Record Does not exist", "RandomFile", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
FileGet(1, person, Val(txtRecNum.Text))
txtSSN.Text = person.SS
txtName.Text = person.name
txtTele.Text = person.Tele
End If
End Sub
I AM ALSO HAVING A PROBLEM WHEN TRYING TO ALLOW UPDATES TO A SPECIFIC RECORD, WHEN I LOOK UP A RECORD NUMBER AND THEN
TRY SAVING THE CHANGES IT DOES NOT CHANGE THAT SPECIFIC RECORD WHAT IT IS DOING RIGHT NOW IS IT WILL ADD IT TO THE FILE
BUT IT THEN APPENDS OR ERASES THE NEXT FILE SO IF I HAD 3 RECORDS AND I SAY I WANNA CHANGE THE 1ST REC, IT WILL APPEND OR ERASE ITSELF TO THE 2ND POSITION IN THE FILE AND THE PREVIOUS 2ND RECORD WILL NOW BE DELETED. ???? IT IS HOWEVER SAVING JUST
NOT TO THE RIGHT INDEX
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'**********************************************
'THIS SUBROUTINE WILL UPDATE ANY CHANGES
'THE USER ENTERS TO A SPECIFIC RECORD
'HE/SHE FINDS AFTER SEARCHING BY REC NUM
'**********************************************
'Update the information of an person.
' person.RecordNum = Val(txtRecNum.Text)
person.name = txtName.Text
person.SS = txtSSN.Text
person.Tele = txtTele.Text
FilePut(1, person, )
End Sub
modified on Wednesday, December 9, 2009 3:18 AM
|
|
|
|
|
WHy does this assignmnet reek of homework??
|
|
|
|
|
Sorry its just a program needed for class and I have it almost working but cant find a way around my problem I am running into
|
|
|
|
|
OK, this is the first time I've ever heard of anyone teaching FileGet/FilePut in a VB.NET class. The only time I've ever seen anyone actually using it is in VB6 projects converted to VB.NET.
You don't need the record number in the data since each is going to be at a certain position anyway. When the use enters a record number, it'll go and get that record from the file, even if it's empty. So, there's no need to check the RecordNumber returned by the person object because you already got the record at that position.
The question becomes, did you get anything back from the record? Is person returning Nothing?
Your second problem is in the FilePut call. You're not telling FilePut which position in the file to write the record to.
|
|
|
|
|
hi,
pls anyone try to solve my problem... i need to fetch some thousands of records and insert/export that to excel file using vb.net...
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim recArray As Object
Dim strDB As String
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer
strDB = "UNOGI\UNO;database=Test;uid=sa;pwd=welcome3#" 'here am getting the following error "Could not find installable ISAM."
cnt.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDB & ";")
rst.Open("select top 10000 * from Test.dbo.CustomerDetail", cnt)
xlApp = CreateObject("Excel.Application")
xlWb = xlApp.Workbooks.Add
xlWs = xlWb.Worksheets("Sheet1")
xlApp.Visible = True
xlApp.UserControl = True
fldCount = rst.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next
If Val(Mid(xlApp.Version, 1, InStr(1, xlApp.Version, ".") - 1)) > 8 Then
xlWs.Cells(2, 1).CopyFromRecordset(rst)
Else
recArray = rst.GetRows
recCount = UBound(recArray, 2) + 1
For iCol = 0 To fldCount - 1
For iRow = 0 To recCount - 1
If IsDate(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = Format(recArray(iCol, iRow))
ElseIf IsArray(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = "Array Field"
End If
Next iRow
Next iCol
' Transpose and Copy the array to the worksheet,
' starting in cell A2
xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = _
TransposeDim(recArray)
End If
' Auto-fit the column widths and row heights
xlApp.Selection.CurrentRegion.Columns.AutoFit()
xlApp.Selection.CurrentRegion.Rows.AutoFit()
' Close ADO objects
rst.Close()
cnt.Close()
rst = Nothing
cnt = Nothing
' Release Excel references
xlWs = Nothing
xlWb = Nothing
xlApp = Nothing
End Sub
Function TransposeDim(ByVal v As Object) As Object
' Custom Function to Transpose a 0-based array (v)
Dim X As Long, Y As Long, Xupper As Long, Yupper As Long
Dim tempArray As Object
Xupper = UBound(v, 2)
Yupper = UBound(v, 1)
ReDim tempArray(Xupper, Yupper)
For X = 0 To Xupper
For Y = 0 To Yupper
tempArray(X, Y) = v(Y, X)
Next Y
Next X
TransposeDim = tempArray
End Function
in the above code i got some error, if anyone knows any other way pls try to help me resolve as soon as you can... thanks in advance..
|
|
|
|
|
|
do u know any other way to do this bulk insert operation to excel sheet from vb.net
|
|
|
|
|
You've got the only way to do it.
Also, be careful you're not adding so many rows of data to a worksheet that Excel runs out of memory.
You also didn't say what the error message was.
|
|
|
|
|
Try to use Spire.DataExport - it is c# data export component that supports data export into MS Excel,MS Word, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format.
|
|
|
|
|
I have a aspx application that has some batch sql updates. Need to see status of information that is processed. Is there a equivalent of the Application.DoEvents() in aspx?
|
|
|
|
|
No, for obvious reasons.
If you want to update the web page with the status, you'll have to do it using Ajax or some other page reload. The update would have to be done using a background threaded component.
Ask this question in the ASP.NET forum. What you're asking has nothing to do with VB.NET.
|
|
|
|
|
Hmmm ... You've got a very common problem, especially when you go from a desktop environment to a web environment. I haven't solved this for myself yet, but I think what you can do is create a class, which has an update method that performs your batch update. When you write this method, you will need to execute the update in a separate thread, so that you can return control to your application while the update is running. I think you could then create a event that could be raised when the job is finished.
Or ...
What about creating a SQL server job that performs the update and your web app just invokes the job ? This way the SQL server handles the background execution and doesn't hold up your web page. You could even write to a table (JOB_STATUS)the progress of the job (rows processed) and your web page could check this page periodically for new status.
Check out Microsoft's sp_start_job
http://msdn.microsoft.com/en-us/library/ms186757.aspx[^]
|
|
|
|
|
I have a datagridview and coulmn2 is showing the values like 23.34234, 3.3333 like wise. I tried the following but failure.
I need to format like 23.34 or 23.35
Private Sub MyDataGrid2_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles MyDataGrid2.CellFormatting
If e.ColumnIndex = 2 And e.RowIndex = 1 Then
'e.Value = String.Format("###,###.00", e.Value)
End If
End Sub
Is there any better ideas for me?
|
|
|
|
|
Well, you're code skips a few things, like checking if e actually has a value to format. You also don't tell the DGV that you applied formatting to the value, and you don't do any error checking in case a non-numeric value is passed in to your column.
Private Sub MyDataGrid2_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCelLFormattingEventArgs) Handles MyDataGrid2.CellFormatting
' Only apply formatting to a value that exists...
If e.Value IsNot Nothing Then
If e.ColumnIndex = 2 Then
' Format the value to 2 decimal places using culturally-aware format.
e.Value = String.Format("{0:N2}", e.Value)
e.FormattingApplied = True
End If
End If
End Sub
I didn't both with any error trapping in this example. I leave that as an excersize to you.
|
|
|
|
|
Thank You Very....Very....Much To You !
Those remote connections,etc...from .net I learned from you...!
All Your Guidences....Gave Great Knowledge to improve myself.....!
You have to live good, Dave..!
My Best Wishes From
PARAMU
|
|
|
|
|
Dear All,
I do not know asp or c#. i just use visual basic.
now i develop an application in order to send mail with attach file to multiple recipience.
I take some sample code from websites for study as well but it still can not.
my code is:
With Mail
.From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName)
.To.Add(mTo.Trim)
.Priority = pPriority
.IsBodyHtml = pIsBodyHtml
If mCC <> "" Then .CC.Add(mCC.Trim)
If mBCC <> "" Then .Bcc.Add(mBCC.Trim)
.Subject = CStr(mSubject).Trim
.Body = mBody.Trim
.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
End With
Smtp.Host = CStr("mail.company.com")
Smtp.Port = 888
Dim myCredential As New System.Net.NetworkCredential("golden.meas", "gggggggggg")
Smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
Smtp.Credentials = myCredential
Smtp.Send(Mail)
End With
================
After i sent i can not know weather it success or not.
I test to send to my friend mail but can not know weather is success or not and we do not get.
what any sold for this ? And do you have any source code related it ?
Thanks for your help...
Best regards,
VB.Net
|
|
|
|
|
Have a look ! Just I found in MSDN, Answered by Martin, also it will save the mail message as textfile.
Imports System.Net.Mail
Imports System.IO
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailInstance As MailMessage = New MailMessage("FromMailAdress", "ToMailAdress")
Try
mailInstance.Subject = "This is mail subject"
mailInstance.Body = "This is mail body content"
mailInstance.Attachments.Add(New Attachment("filename")) 'Optional
Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host
mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password")
mailSenderInstance.Send(mailInstance)
mailInstance.Dispose() 'Please remember to dispose this object
Catch ex As Exception
MessageBox.Show(ex.Message)
Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt")
sw.WriteLine(mailInstance.From)
sw.WriteLine(mailInstance.To)
sw.WriteLine(mailInstance.Subject)
sw.WriteLine(mailInstance.Body)
sw.WriteLine(mailInstance.Attachments)
sw.Close()
End Try
End Sub
|
|
|
|
|
Thanks Paramu,
In that source is send to only one mail right ?
it seems to me that it has no Cc and Bcc.
If I would like to send to multiple recipienceand
,Cc,Bcc and with attach multiple files, what should i do?
On the other hand when i test to send it by this code which copy from you:
Imports System.Net.Mail
Imports System.IO
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailInstance As MailMessage = New MailMessage("MyEmailAddress", "RecipienceAddress")
Try
mailInstance.Subject = Trim(Me.txtSubject.Text)
mailInstance.Body = Trim(Me.txtBody.Text)
mailInstance.Attachments.Add(New Attachment("D:\11112009204.jpg"))
Dim mailSenderInstance As SmtpClient = New SmtpClient("mail.tmic.com.kh", 587)
mailSenderInstance.Credentials = New System.Net.NetworkCredential("myLongAccount", "MyPassowrd")
mailSenderInstance.Send(mailInstance)
mailInstance.Dispose() 'Please remember to dispose this object
Catch ex As Exception
MessageBox.Show(ex.Message)
Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt")
sw.WriteLine(mailInstance.From)
sw.WriteLine(mailInstance.To)
sw.WriteLine(mailInstance.Subject)
sw.WriteLine(mailInstance.Body)
sw.WriteLine(mailInstance.Attachments)
sw.Close()
End Try
End Sub
It got message error that "Syntax error in parameters or arguments. The server response was: Authentication failed: malformed response"
what is that problem ?
VB.Net
modified on Tuesday, December 8, 2009 9:44 PM
|
|
|
|
|
Dear All,
I need help regarding , i want to save a csv file into sql 2000 database in a single field as image datatype using VB6.0 , how should i proceed i m not getting it.
Parag
|
|
|
|
|
By using ADO, there's an example on uploading files here[^].
Good luck
I are Troll
|
|
|
|
|
This works only if i want to upload image but when i try to upload csv/excel/pdf/audio file then it gives error at LoadFileFrom command as "file could not be open."
Parag
|
|
|
|
|
Parag Raibagkar wrote: This works only if i want to upload image
Wrong. An image is nothing but a stream of bytes, just like any other file. If you give the LoadFromFile method just the filename, it's assuming that the file is in whatever the CurrentDriectory is. Instead of trying to change the current directory, give the LoadFromFile method the fully qualified path to the file you're trying to upload into the database.
|
|
|
|
|