|
Hi ,
Thanks for sending the code but it gives an error
[Microsoft][ODBC Microsoft Access Driver] Wrong number of arguments used with function in query expression 'isnull (max(orderno),0)'.
|
|
|
|
|
The problem is that if your query does not return any results, there will be no rows, and therefore no value can be assigned to your integer.
Using ISNULL, will not necessarily work either. It also can return zero rows.
So you can either count the rows after AjitMourya wrote: rss.Open("select max(orderno) As ono from measurementpant where custno='" & txtcustno.Text & "' AND length<>0 ")
and before
AjitMourya wrote: no = Convert.ToInt32(rss.Fields("ono").Value)
or you can force a result in your query, and then take that into account when you assign the value to your integer:
rss.Open("select (1 + ISNULL(max(orderno),0)) As ono from measurementpant where custno='" & txtcustno.Text & "' AND length<>0 ")
no = (Convert.ToInt32(rss.Fields("ono").Value) - 1)
My advice is free, and you may get what you paid for.
|
|
|
|
|
HI
I am new to coding and I was in need of a little help.
I have a contacts form and there is a textbox "tbNewContact.Text" and two buttons. When one buttone is pressed I was wanting the following to happen. An sql connection has been opened at form_load.
When the user enters a contacts name it does a check on the database table. If it returns any rows then it displays a message.
If not rows returned then it will submitted the contact to the SQL database.
But it does not work. I get the message "Contacted Added" but nothing has been.
If the code is cra then sorry like i said Im new to this.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddContact.Click
'Check Contacts
Dim SQLSearch As SqlCommand = sqlconn.CreateCommand
Dim sqlinsert As SqlCommand = sqlconn.CreateCommand
SQLSearch.CommandText = "SELECT * FROM Contacts WHERE ContactName = '%" & tbNewContact.Text & "%';"
Dim SQLDR As SqlDataReader = SQLSearch.ExecuteReader
If SQLDR.HasRows Then
MsgBox("That contact name already exists." & tbNewContact.Text & _
"If you wish to add this contact, please cancel and choose 'Add Existing Contact'", MsgBoxStyle.Information)
SQLDR.Close()
Else
sqlinsert.CommandText = "insert into contacts (contactName) values '%" & tbNewContact.Text & "%';"
MsgBox("Contact Added")
Exit Sub
End If
SQLDR.Close()
End Sub
Thansk In advance
|
|
|
|
|
The error is here:
sqlinsert.CommandText = "insert into contacts (contactName) values '%" & tbNewContact.Text & "%';"
You should change it to:
sqlinsert.CommandText = "insert into contacts (contactName) values ('" & tbNewContact.Text & "');"
Also note that opening the connection at form startup and keeping it open is not a good idea. It may time out or suffer from other connection problems.
You should open a connection each time you need to access the db, and then close it.
Do not worry about opening too many connections, since you will not: pooling and re-using of existing connections is done at driver level.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi
Thanks for your responce but that does not seem to work either?
|
|
|
|
|
As a try, you may check
dim My_Value as string=trim(tbNewContact.text.tostring)
And
sqlinsert.CommandText = "insert into contacts (contactName) values '%" & My_Value & "%'
|
|
|
|
|
After the user has checked a box and the program has done it's thing, I want to uncheck that box.
I thought this would work, but nothing happens.
CheckBox1.CheckState.Equals(False)
Visual Studio 8
Version 9
Thanks.
modified on Saturday, August 15, 2009 1:07 PM
|
|
|
|
|
Seriously, pickup a beginners book on VB.NET and work through it. The Equals method checks to see if the object that you called Equals on is equivilent to the object in the parenthesis. Essentially, you asked in the value of CheckState is equal to False. It returns a True/Value value (which you completely ignored.) It does NOT set the value of CheckState to False. To do that, you write this:
CheckBox1.CheckState = False
|
|
|
|
|
Thanks for the quick reply.
I have read, and worked though a few books.
I still don't comprehend some things.
I thought this was an easy task, but I kept going down the wrong path.
I have Step by step 2003, by JulianTempleman
Programers Refrence by Dan Rahmel
Step by step 2008 by Michael Halvorson
Thanks again.
|
|
|
|
|
Hi
I have set combo's Setfocus property on an button click.But when i click another exit button ,I have to click 2 times to exit the application .i wanna exit on just single So kindly help me anyone please????????
[Look the code is in VB6]
Thanks in advance
|
|
|
|
|
mdrizwan_1 wrote: So kindly help me anyone please
Not without seeing some code. It could be anything and I'm no mid reader, nor is anyone else to the best of my knowledge.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi,
I am developing outlook add-in application in which i need to add new contacts from XML file into outlook and all updated contact should be Read Only. I added Contacts from XML successfully But not able to make Read only.
So my problem is that how to make Contact Read only so that no body can change Outlook Contacts.
Urgently
Thanks in advance.
Regards
Dharmchand Dhingra
|
|
|
|
|
Hello Everybody
As m new to Classic Asp kindly help me?
I m working on VB6 Environment.Here i have an Google mapping application been developed using Classic ASP and Java Script.The problems is that when i run this application it takes time in load the entire info on the page,So i need your help ,How can i increase its performs by reduce the delay,(If possible can i modify it using Ajax or something Else? Suggestion....)
Thanks In Advance
Rizwan
|
|
|
|
|
That depends on where the delay is. If it's with the Google server that your waiting for, there's nothing you can do to speed this up.
|
|
|
|
|
hi there,
i am using crystal report 10 to generate using VB 2008. I have a problem in generating data for crystal report when datagridview item is selected. my datagridview gets data from a dataset called ds. any help?
|
|
|
|
|
You haven't provided enough information to tell you anything useful. What's the problem you're having? What are the error messages, if any?? What does the code look like where the error was generated?? What does selecting an item in the DGV have to do with generating the report?? ...
|
|
|
|
|
For i As Integer = 0 To DataGridView1.Rows.GetRowCount(DataGridViewElementStates.None) - 1
If DataGridView1(2, i).Value Is DBNull.Value Then
MsgBox("you didn't Select Student ID", MsgBoxStyle.Exclamation, "Student ID Missing")
Else
'displaying selected student data on crystal report
If DataGridView1(3, i).Value.ToString = "A" Then
rpt.setdatasource(ds) 'ds is my dataset where student table is found
dim myparams as new new ParameterFields()
dim myparam as ParameterField = new ParameterField()
dim myDiscretevalue as new ParameterDiscreteValue()
'// Set the ParameterFieldName to the name of the parameter
'// created in the Field Explorer
myParam.ParameterFieldName = "StudFullName
'// Add first student
myDiscreteValue.Value = "Peter"
myParam.CurrentValues.Add(myDiscreteValue)
'// Reuse myDiscreteValue, and assign second student
myDiscreteValue = new ParameterDiscreteValue()
myDiscreteValue.Value = "Smith"
myParam.CurrentValues.Add(myDiscreteValue);
'// Add param object to params collection
myParams.Add(myParam)
'// Assign the params collection to the report viewer
myCrystalReportViewer.ParameterFieldInfo = myParams
'// Assign the Report to the report viewer.
'// This method uses a strongly typed report,
'// but other methods are possible as well.
myCrystalReportViewer.ReportSource = MyReportObject
end if
and the problem is it says no valid table. can u help me in correcting this code so that when datagridview row is selected, data for the selected student is displayed on the report
thanks
|
|
|
|
|
You haven't said which line the error throws on.
I also don't use CrystalReports, so I don't know how much help I'm going to be.
|
|
|
|
|
1.With your application you have to create one Dataset-[XSD] file, and create a datatable there and the crystal reports field has to be from xsd.
2.After from a button click(), display thru a crystalreportviewer, but the data from datagridview selected row has to send to dataset which one you have already created from form ds.
Dim ObjRpt As New CrystalReport1
ObjRpt.SetDataSource(DS62.Tables(0))
CrystalReportViewer1.ReportSource = ObjRpt
CrystalReportViewer1.Refresh()
CrystalReportViewer1.Visible = True
From the above, DS62 is the dataset in form. My xsd filename is Dataset1 and Datatable is Datatable1.
|
|
|
|
|
Reply to the original poster, not me. I just got the notification that you replied. The OP didn't.
|
|
|
|
|
Check my previous reply. I hope that can helps you !
|
|
|
|
|
|
Hi all,
This is my first real attempt at playing with networking comms, so be gentle!
I have been struggling to get this to work. I have looked at the examples on here, and countless others returned by Google, i have also been reading the msdn documents, and what i have looks logical and partly works.
What i am trying to do is;
1) Open the TCP connection
2) Read the Byte stream and pass off blocks of bytes for processing elsewhere.
I can succesfully open the connection and async callback are entering the stream reader so I *think* the problem lies in there. I don't know how many different things i have added/removed but still not reading the bytes.
Any clues as to what i am doing wrong?
Private Client As New TcpClient
Private _readBufferSize As Integer = 128
Private ClientStreamBuffer(_readBufferSize) As Byte
Public Event DataToProcess(ByVal Buffer() As Byte)
Public Event ConnectionStateChange(ByVal Connected As Boolean)
Async connect call
Public Sub Connect(ByVal Host As String, ByVal Port As String)
Try
Client.NoDelay = True
Client.ReceiveTimeout = 30
Client.BeginConnect(Host, Port, AddressOf ConnectionResponse, Nothing)
Catch ex As Exception
Debug.WriteLine("Connect Failure: " + ex.Message)
End Try
End Sub
Connection delegate
Private Sub ConnectionResponse(ByVal Ar As IAsyncResult)
Try
'accept the connection
Client.EndConnect(Ar)
RaiseEvent ConnectionStateChange(Client.Connected)
'start an async read of the clients datastream
Client.GetStream.BeginRead(ClientStreamBuffer, 0, _readBufferSize, AddressOf ClientStreamReader, Nothing)
Catch ex As Exception
Debug.WriteLine("TCPIP Connection Failed: " + ex.Message)
End Try
End Sub
Stream Reader;
Private Sub ClientStreamReader(ByVal Ar As IAsyncResult)
Try
Dim bytesRead As Integer = Client.GetStream.EndRead(Ar)
Dim bytesToProcess(bytesRead - 1) As Byte
'Copy data off the buffer into the process array
Array.Copy(ClientStreamBuffer, 0, bytesToProcess, 0, bytesRead)
'do something like raise an event with BytesToProcess
RaiseEvent DataToProcess(bytesToProcess)
'Start the read again
Client.GetStream.BeginRead(ClientStreamBuffer, 0, _readBufferSize, AddressOf ClientStreamReader, Nothing)
Catch ex As Exception
Debug.WriteLine("StreamReader Problem: " + ex.Message)
End Try
End Sub
The next method is what i would use to handle the individual blocks of bytes from the stream;
Handling it locally at the moment, but will probably reside in a different place later. just using it to see what byte blocks are being raised.
Private Sub TCPIPComms_DataToProcess(ByVal Buffer() As Byte) Handles Me.DataToProcess
Debug.WriteLine("Data Buffer Available bytes: " + Buffer.Length.ToString)
'Do something with the bytes...............
End Sub
|
|
|
|
|
First thing I see is that you're not passing anything in as the state tracking object in your BeginConnect and BeginRead calls. You're trying to substitute using class-level objects for state tracking and misusing them. I think that is what is causing your problem.
I normal do something like this. Create a custom object that contains the buffer and Stream being read.
Public Class AsyncReadTracker
Public buffer(20480) As Byte
Public s As Stream
End Class
I create a method to start the Async Read of the incoming stream, creating a new tracking object and passing the buffer in the object to the BeginRead method, as well as the callback delegate and the tracking object itself. You'll see why in a second...
Private Sub StartAsyncRead(ByRef st As Stream)
Dim art As New AsyncReadTracker
art.s = st
Dim ReadAsyncCallback As New AsyncCallback(AddressOf ReadCallback)
st.BeginRead(art.buffer, 0, art.buffer.Length, ReadAsyncCallback, art)
End Sub
In the read callback delegate, the IAsyncResult parameter is there for a reason. Use it. The tracking object will pass the buffer that contains the data and the stream that it was read from to the next call of BeginRead. When BeginRead calls the ReadCallback delegate, it'll pass the tracking object to the delegate. The delegate will pass the stream back to the new call to StartAsyncRead so the same stream can continue to be read.
Private Sub ReadCallback(ByVal asyncResult As IAsyncResult)
Dim art As AsyncReadTracker = DirectCast(asyncResult.AsyncState, AsyncReadTracker)
Dim bytesRead As Integer = art.s.EndRead(asyncResult)
Dim enc As Encoding = Encoding.ASCII
Dim s As String = enc.GetString(art.buffer, 0, bytesRead)
' Do something with the data you just got...
' Now start the Async Read process on the stream we've been using, all over again.
StartAsyncRead(art.s)
End Sub
|
|
|
|
|
Dave,
thanks for the detailed prompt response, i will disect my code and implement your recommendations, and hopefully it will work!
Thanks again,
dave
|
|
|
|