|
What you have given me is the connection string. But I am also having problems with the declaration of the variables.
Do you know how to do that, if you do, I will really appreciate your assistance. I have made several attampts to do this but it seems I am stuck. All I need is to know how to declare the variables and how to connect - that's all!
Jesus Christ is Lord!
|
|
|
|
|
Sorry I have not used access for 10 years but your syntax seems to indicate you are using VB6, recordsets do not exist in .Net, if this is the case I can only offer you a paddle.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have one application in vb6.I want to convert it in vb.net.I have been trying alot to use recordset but giving error like arguments are of wrong type,are of out range or conflict with one another.What i do?
code:
If rs1.State = 1 Then rs1.Close()
rs1.Open("select * from UserTable where User_Id ='" & Trim(TextBox1.Text) & "' and User_Password='" & Trim(TextBox2.Text) & "'")
If rs1.EOF = True Then
MsgBox(" Password is not correct, check again .....?", vbCritical + vbOKOnly, "")
i = i + 1
If i = 3 Then
MsgBox("Sorry, you have lost your time.....", MsgBoxStyle.Exclamation)
Application.Exit()
End If
Else
MDIParent1.Show()
Me.Hide()
End If
|
|
|
|
|
VB no longer has recordsets. You need to read up on ADO.NET to see what is currently available as there are many ways to get data to and from a database now to cater for different scenarios.
Also, the code you showed is susceptable to SQL Injection Attacks, you should read up on them also so you can protect your application. This article will show you what SQL Injection Attacks are and how to prevent them[^].
|
|
|
|
|
recordset is easy to use.i am not feel comfort with datasets.If any one know plz solve.
|
|
|
|
|
lahsiv wrote: i am not feel comfort with datasets
There are other ways to access data in .NET.
DataReaders, for example. Or you could use the Data Access Application Block (part of the Enterprise Library). Or you could use an ORM (Object Relational Mapping) tool such as XPO or NHibernate. Or... Or.... Or....
|
|
|
|
|
lahsiv wrote: .i am not feel comfort with datasets.
Tough - get used to it, as a programmer you will continiously need to learn new things. You have 2 choices here, upgrade your skills or quit.
Dataset, datatable, dataview are the tools you are going to have to work with in .net. Unless you to linq of course .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Dataset, datatable, dataview are the tools you are going to have to work with in .net. Unless you to linq of course
There are even alternatives to that.
|
|
|
|
|
Colin Angus Mackay wrote: There are even alternatives to that.
Elaborate please - I may be guilty of finding the first successful method and ignoring other possibilities. I often do this and am continiously surprised when someone comes up with a different method.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Elaborate please
DataReaders for starters - Read my other post in this thread, the one to the OP, where I list a bunch of ways.
|
|
|
|
|
I consider datareaders as part of the datatable/set infrastructure because dataset.fill uses a reader under the hood anyway.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I consider datareaders as part of the datatable/set infrastructure because dataset.fill uses a reader under the hood anyway.
If that is your reasoning then there are no other ways because everything uses a DataReader "under the hood".
|
|
|
|
|
Can you advise me on which line you are getting here ? Please post here error message also.
Parwej Ahamad
R & D: REST services with WCF
|
|
|
|
|
after filling textboxes,click on the login button then i got message
|
|
|
|
|
lahsiv wrote:
If rs1.State = 1 Then rs1.Close()
Where did people develop the habit of using global variables for recordsets and using 'lazy close'? I've had to deal with such code, but I wonder how such sloppy coding came into common practice.
Doing things with a datareader is really pretty easy. Opening a connection by creating a new Odbc.OdbcConnection(connectString) . Then create a new Odbc.OdbcCommand(theCommandString, theConnectionObject) . Rather than appending string arguments, insert them using "@@" syntax, e.g. Dim MyCmd as New Odbc.OdbcCommand("SELECT User_Password from UserTable where User_ID=@@UserID", myConnection) . Then fill in the parameters using the Cmd.Parameters.AddWithValue(name, value) method, e.g. Cmd.Parameters.AddWithValue("@@UserID", Trim(Textbox1.Text)) .
Once the command object is loaded with parameters, you may use Cmd.ExecuteNonQuery() to perform a command that won't return anything, Cmd.ExecuteScalar() to perform a command that will return one object, or Cmd.ExecuteReader() to return an iDataReader object. Use theReader.read() to fetch each record (including the first) into the reader object; it will return false on EOF. After each record is read, you may use theReader(0) to read the first field, theReader(1) to read the second, etc. If your query is properly designed, you will know in advance how many fields will be returned and what they will be.
modified on Monday, August 18, 2008 6:37 PM
|
|
|
|
|
Excellent response, but he does not want to use datatables and datasets, he knows recordsets and is unhappy because MS has changed from the VB6 methods
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The approach I described works pretty similarly to recordsets for reading. The syntax is different, and one does a 'read' before each record instead of a 'movenext' after, but otherwise things are pretty similar. It does not use datatables or datasets.
I'm not sure what the nicest way is to do updates without learning to use DataWriter objects, though. Using INSERT and UPDATE queries isn't particularly difficult, but it doesn't seem like the fastest thing in the world.
|
|
|
|
|
supercat9 wrote: DataWriter objects
Whats a datawriter?
supercat9 wrote: Using INSERT and UPDATE queries isn't particularly difficult
How else do you get the data to and from a database?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Whats a datawriter?
(blush) When I started using DataReaders, I thought there was a corresponding class of DataWriter objects I simply didn't understand. Having looked through the documentation, it seems that I was confusing read/write DataAdapters with DataWriters, as I don't think the latter concept exists.
Mycroft Holmes wrote: How else do you get the data to and from a database?
I think there exists some means of doing bulk-data inserts into a cursor or something. Using one INSERT or UPDATE query per record seems to run rather slowly, even when I combine multiple queries into a single command. BTW, I know this is the VB forum rather than the SQL forum, but I'll ask anyway: is there a good way to specify, when inserting data into a table with a uniqueness constraint, that new data should overwrite old data? For example, if I'm updating a record associated with a hardware token (so I know that no other task will simultaneously update the same record) two approaches that would be workable are:- Delete the old record and write a new one.
- Try an 'Update' on the serial number, and if no records were updated, do an 'Insert'.
The first approach is rather ugly and creates unnecessary work at the server removing and re-adding data to the indexes. The second approach would be cleaner except that it doesn't allow for easy consolidation of multiple updates.
|
|
|
|
|
supercat9 wrote: doing bulk-data inserts into a cursor or something
There is a bulk copy method which ONLY inserts data, not sure which tech it uses under the hood. This is excellent for loading voluminous data. There is no bulk update facility except using a query.
supercat9 wrote: is there a good way to specify,
Part of the utilities I use is a code builder that creates 2 stored procs for every table, it assumes that the 1st field in the table is an ID/identity field (unique constraint). The DAL passes in a 0 or record number, if the IS is 0 then the proc does the update else it inserts. You can also use a various strategies in the proc to detect the existence of a unique constraint (select count(*) where... or if exist select * from ...).
Never do the delete/insert thing, always do the update and have an index on the unique field. Why, because the loookup to delete the record can cost more than the update especially if there are foreign keys, and then you get the insert for free.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hi Folks I am Using Visual Basic within Excel and have encountered a problem I hope someone can help with
I have a table of Bills and months ie
Month1 Month2 ........
Bill 1 0 0
Bill 2 0 0
Bill 3 0 0
For each bill there is a value in the month column.
Each Cell starts with a value of 0
I create a NEW worksheet ie - NEWSHEET and this passes a formula back to cell C3 on sheet Bills
C3 before = 0
C3 after = NEWSHEET!L5 - showing the contents of Cell L5 ON Sheet NEWSHEET
When I delete the NEWSHEET for whatever reason the value of C3 changes to this:-
C3 becomes =#REF!L5
In itself this isn't a problem as I was expecting this to happen however once the cell contains =#REF!L5
I want to run a small script to look at each cell and if the value of the cell is =#REF!L5 then I want to reset the value to zero
if the value of the cell isn't =#REF!L5 then I wish to leave the value alone
Hope this makes sense and that someone can assist
|
|
|
|
|
Look up functions IsNA, IsError... you can use those to check the cell values and modify contents if needed.
HTH
|
|
|
|
|
Hi all,
first i stored employee name into an array from start_cell_number to end_cell_number like this
Dim testarray() As String = New String(47) {}
For i = start_cell_number To end_cell_number mean (4 to 8)
testarray(i) = (dr("User_Name").ToString())
Next
then tried to findout total number of user name repeated in an array like this
Dim noOfTimes As Integer = 0
For Each str As String In testarray
If str = Label1.Text Then
noOfTimes = noOfTimes + 1
End If
Next
here iam getting total number of user name repeates in an array but when iam putting below line in loop block iam getting result like this
Response.Write(noOfTimes.ToString() + "" + Label1.Text)
00001234444444444444444444444444444444444444444444444444444 but i have to need result like this
00001234000000000000000000000000000000000000000000000000000 becuase username only repeated 4 times.
kindly suggest me where iam doing mistake.
thanks in advance
Regards
Rameez
|
|
|
|
|
Hi
When you are filling your array
you are not doing a dr.next() to get the next record?
you have to be careful when your are using this !
e.g
while (dr.next())
{
//make something
}
|
|
|
|