|
Thanks kschuler that seems to answer all my qiestions
|
|
|
|
|
I'm trying to read a datagridview and post the changes back to the SQL database. Does anyone have some straightforward code that will work. I'm a newbie in VB.net.
|
|
|
|
|
Hi Roger,
When people ask for "Straightforward code" it's kind of impossible to respond. All code is tailored to an individual need and no one is going to have EXACTLY the code you want. (Nor will they create it for you if you are not willing to put some effort into it yourself.) The best way to start a project like this is to read some articles about what you are doing. You can search codeproject for articles, like this.[^]. Then as you implement code you've found in the article, if you run into problems post your code and error messages and a description of what your program is doing and what you want it to do. Then we can help you. Hope this gives you a good place to start.
|
|
|
|
|
I think it's a fair question, and one that has recently been much on my mind.
In VB6, making an grid you could update was completely trivial, under VB.NET, after several hours, I'm completely baffled.
Are we supposed to hand-code an add / update / insert statement, somehow connect it to something? Is a "CommandBuilder" somehow involved?
Is there some "do it automatically" switch somewhere I'm not pushing?
adapter.update(dataset) doesn't throw an error, and doesn't do anything either.
You'd think someone would have posted a sample project, where you put the query in a textbox, click 'execute', and get a datagridview you can edit, like you could do in 5 minutes in VB6. There are DataGrid based examples from VS2005, but I haven't seen any for the DataGridView. At present, my guess is because this is next to impossible with the DataGridView.
Near as I can tell, I'm doing what the instructions say, but nothing happens. Maybe NPGSQL doesn't work?
|
|
|
|
|
I agree with you, that the question is valid. I just felt like it was too broad a topic and requires more information to decently answer in the forums as is.
I haven't really ever used VB6, so I'm not aware of the differences between it and VS2003 or above. As for how to add the add/update/insert statement easily, it also depends on the data provider you are using. If you use OleDb or SqlClient you should be able to use a CommandBuilder. You just need to write the Select SQL Statement, set it to the DataAdapter, and then put this statement (if using SqlClient provider):
Dim cb As New SqlClient.SqlCommandBuilder(myDataAdapter)
before you call the update method of the DataAdapter object. It's also a good idea to clean up after the update with this statement:
cb.Dispose()
I'm not sure if it works exactly the same way if you are working primarly in design mode, as I mostly code all my database stuff instead of using the visual studio designer to drag and drop DataAdapters, Connections, etc.
Since there are so many possible scenarios, it's hard to give more advice than this. Which is why it's so much better to post your code when asking for help. Please post what you have for your update and we can give you some help and advice on what is not working.
|
|
|
|
|
Aha!
That did it. I added:
dim cb as new NpgsqlCommandBuilder
cb = New NpgsqlCommandBuilder(m_da)
Where:
m_da is a NpgsqlDataAdapter control in the design view.
m_cmd is a NpgsqlCommand in the design view.
m_ds is a System.Data.Dataset in the design view.
New code is after putting the SQL Select statement into m_cmd, and before m_da.fill(m_ds)
Thanks very much, this is *much* simpler than some sites made it look.
These seems more complicated than it was in VB6. Then, you had a datacontrol and a grid. Load the datacontrol's connection string, set the datasource to the query, 'refresh', all done.
Now I have something that works like the demo I described, but it's probably not a very good example, don't know which of the things I've pulled from the web actually contribute to it working yet.
At the risk of maybe should have clicked "Rant..."
I've only recently started using VB.NET. Started with VB in VB3. Stopped in VB6, because the upgrade wizard crashed on my 300 form, 250 modules/classes application. As of VS2008, upgrade wizard didn't crash, but it's looking like an 80% rewrite; what the upgrade wizard left looks like a transporter accident. data binding (in the converted application) is demolished, usercontrols didn't port for beans, deep heavy sigh.
My impression at this point is that VB has lost it's direction - it used to be going toward 'Simpler', ever easier to build stuff. Now it's trying to compete (and doing well at it) with Java and C++. I spent a decade programming in each of those, and chose VB6 for my own projects, because I like results more than tinkering with strongly typed stuff. I liked the direction VB was going, but it took an abrupt left turn with VB.NET.
Hopefully I'll get used to it. Probably slightly easier than relearning Java.
|
|
|
|
|
In one of the regular Spreadsheets I am asked to do, I need a Column that does a complicated SUMming.
There are a number of columns of data, between 2 and, say, 10 columns (Depending on other factors).
In Each Column there is a set of data such as Land Price, Build Cost Prelims etc. At the Head of Each column is a number representing How Many of Each Type.(The column data is shown for the cost of 1 of each type).
Currently I am having to type in the cell the following...
=($G$5*G8)+($H$5*H8)+($I$5*I8) etc (not too bad with three columns, but if there are 10 or more it takes a while!
(Because of the $'s I can Copy Down with impunity)
So at the end column for each ROW I get a total cost for the project on each of the Parts.
I would like to do away with having to waste my life and that of my keyboard by having a Function that I can put into the Totals Column.
Something like =FACTOREDTOTAL(5,("G5"),6)
This being there are 5 columns of data, locked at G5 for the first column (but moving 1 column along each iteration), starting 6 columns to the left.
Does that all make sense?
OK, I have tried, and tried, I have failed and failed.
I know it must be possible either as a function or as a Macro, but either I am dim or my brain is fried, but has anyone got any pointers to this?
MOD - I can do it as a macro, but I would rather have it as a function!
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
modified on Tuesday, June 2, 2009 10:28 AM
|
|
|
|
|
You could build a function to do this, but why ?
Just keep the complicated formula as a text file on your desktop and monthly type it in. Then copy it down for the number of rows in your spreadsheet.
my 2 cents
|
|
|
|
|
Errr...no
Sometimes it needs only three sections, sometime ten. Once it was 22!
So I get (a*b)+(c*d)....20 more of these...+(xx*zz)
It is too long and too much effort.
A simpler function is better.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
OK. I got it. You're right, too much of a pain in the @ss to do each month.
So what is stopping you from writing the function ?
Jump in head-first into VBA !
|
|
|
|
|
Here is what I have but it is not working yet...
Public Function FACTOREDTOTAL(NumberOfCols As Integer, CellKey As Range, CellsAcross As Integer) As Variant<br />
Dim Answer As Double<br />
Answer = 0<br />
Dim PartAns(NumberOfCols)<br />
Dim AnswerCell As Range<br />
ActiveCell.Select<br />
AnswerCell = Selection<br />
For a = 0 To NumberOfCols<br />
Range.Offset(0, 0 - a).Select<br />
PartAns(a) = Selection.Value * Selection.Range(CellKey.Offset(0, -a)).Value<br />
<br />
Answer = Answer + PartAns(a)<br />
Next a<br />
Range(AnswerCell).Select<br />
Selection.Value = Answer<br />
<br />
End Function
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
Hi all i'm kind of a newbie. I need some help iterating through the records of a random access file . Like a next and previous button, and deleting records in the file.
Here is the code that i have thus far please help.
Next:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Employee As Company, Count As Integer
Filenum = FreeFile()
FileOpen(Filenum, "Filename.dat", OpenMode.Random, , , Len(Employee))
Filenum = frmedit.lblrecord.Text
Count = 1
frmedit.lblrecord.Text = Count
If EOF(Filenum) = False Then
FileGet(Filenum, Employee, Count)
txtcompanyname.Text = Employee.Name
txtstreet.Text = Employee.Street
txtsuburb.Text = Employee.Suburb
txttelephpone.Text = Val(Employee.Telephone)
txtfax.Text = Val(Employee.Fax)
txtemail.Text = Employee.Email
Count = Count + 1
Else
MsgBox("End Of File", MsgBoxStyle.Critical, "Error")
End If
FileClose(Filenum)
End Sub
Previous:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Employee As Company, Count As Integer
Filenum = FreeFile()
FileOpen(Filenum, "Filename.dat", OpenMode.Random, , , Len(Employee))
Count = 1
If Count <> 0 Then
FileGet(Filenum, Employee, Count)
frmedit.txtcompanyname.Text = Trim(Employee.Name)
frmedit.txtstreet.Text = Trim(Employee.Street)
frmedit.txtsuburb.Text = Trim(Employee.Suburb)
frmedit.txttelephpone.Text = Trim(Val(Employee.Telephone))
frmedit.txtfax.Text = Trim(Val(Employee.Fax))
frmedit.txtemail.Text = Trim(Employee.Email)
frmedit.txtncr.Text = Trim(Val(Employee.NCR))
Count = Count - 1
Else
MsgBox("Beginning Of File", MsgBoxStyle.Critical, "Error")
End If
FileClose(Filenum)
End Sub
Delete:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim Employee As Company, FileNum1, FileNum2 As Integer
FileNum1 = FreeFile()
FileOpen(FileNum1, "Filename.dat", OpenMode.Random, OpenAccess.Read, , Len(Employee))
FileNum2 = FreeFile()
FileOpen(FileNum2, "Genx.dat", OpenMode.Random, OpenAccess.Write, , Len(Employee))
Do While Not EOF(FileNum1)
If (Loc(FileNum1) <> Position - 1) Then
FileGet(FileNum1, Employee, )
FilePut(FileNum2, Employee, )
Else
FileGet(FileNum1, Employee, )
End If
Loop
FileClose(FileNum1)
FileClose(FileNum2)
Kill("Filename.dat")
Rename("Genx.dat", "Filename.dat")
End Sub
|
|
|
|
|
...and what's the problem? By the way, Random access files are a thing from the past. I would import the data into a database (Access at least) and manipulate it there.
Regards: Didi
|
|
|
|
|
I need to use random access files as it is for a school project. I whish I could use a database that would have been soooo much simpler but were workin on file handling.
The problem is that the code i posted isn't working don't know if you checked it out but it won't go to the next record or previous record and the delete works sort of but the filenumber isn't deleted and certain fields are just set to "0"
thanx: vurdmal
|
|
|
|
|
Well the first problem I can can see lies here
Count = 1
If Count <> 0 Then
Count is always going to be <> 0 because you've just set it. Maybe Count should be a global variable?
I would also a global variable for the Company object and populate the textboxes depending on it.
|
|
|
|
|
I understand the mistake and it is a stupid mistake actually but how wil i get the current recordnumber into the intger count.
Because I figure if I can do that the fileget wil have the current reccord and a quarter of my problems wil be solved.
Regards: Vurdmal
|
|
|
|
|
I presume Count is the total number of records that can be accessed? In which case I think that in your form load event you need to get this number and assign it to a global variable called 'Count' (sorry if I'm being patronising here but by 'Global' I mean a variable declared outside of any methods). Then declare another variable to keep track of which record you're currently looking at (again, Global).
Hope this makes sense.
|
|
|
|
|
I think that's one of my major problems I don't know how to keep track of the records.
I uploaded my project so you could see what I did, hopefully that would clarify things a bit more.
http://www.filefactory.com/file/ag38fg0/n/Document_editor_rar[^]
If it looks a bit junky it is because I ommited a few functions that hhas no relativiy to this post.
|
|
|
|
|
Well I need to leave now and go home. I will take a look at home if I get chance but, as this is a school project I am not going to give you the solution, I will however point you in the right direction if I can.
|
|
|
|
|
Hi Experts,
I would like to capture Harddisk and processor serial No. apply some algorithm over it and generate a new encrypted ID. Further I like to embed this ID to the installed exe. So that it check everytime the same hardware when it run.
Obtaining Serial No. is partly done by us but I dont know how to join this serial key in exe with encrypted mode.
I am using VS2005 and my project is on Vb.Net.
Thanks in advance.
Jay Khatri
|
|
|
|
|
|
hi didi,
I just have finished my project and started deployment. But I was failed to follow the instructions you had given. Can u explain by example.
Best Regards
Jay Khatri
|
|
|
|
|
I did never tried this myself, but would try it that way, if I had the same problem than you...
So, sorry, no examples from my side...
Regards: Didi
|
|
|
|
|
Hey
Im using an inno script create a setup.exe file.
What I want to do is: use a pascal procedure to get the names of the exe's I want to install and then with the run section run these exe's. The will be done for the dll's and ocx files.
Thanks for any help.
|
|
|
|
|
Akkedis wrote: What I want to do is: use a pascal procedure
So you ask about this in a VB.NET forum?? I think the first place I would ask something like this would be a forum that deal s specifically with InnoSetup. You might want to try their support forums.
|
|
|
|
|