|
Hi
i am facing a problem.
I am working with Visual basic 2005 and Sql Server 2000. I 've created an ODBC for the SQl database.
I have.'add' and 'save' buttond and 'edit' and 'update' buttons and delete, first, next, previous and last.
i wrote the following code. its not working for 'update and 'delete', giving me the following error
INVALID OPERATION EXCEPTION WAS HANDLED
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
But the same code is working for access table, imean for update also.
Somebody please help
Also tell me hw can i use ggrid in Vb2005 for display and edition?
Imports System.Data
Imports System.Data.OleDb
Imports system.Data.Odbc
Imports System.Data.Odbc.OdbcCommand
Public Class Form1
Dim con As New Odbc.OdbcConnection
Dim da As New Odbc.OdbcDataAdapter
Dim ds As New DataSet
Dim maxRows As Integer
Dim inc As Integer
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Clear()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "dsn=alphasql"
con.Open()
da.SelectCommand = New OdbcCommand("Select * from Company", con)
da.Fill(ds, "Company")
maxRows = ds.Tables("Company").Rows.Count
inc = -1
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
Close()
End Sub
Private Sub cmdFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
Else
MsgBox("This is the first Record")
End If
End Sub
Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
con.Close()
con.Open()
da.SelectCommand = New OdbcCommand("Select * from Company", con)
da.Fill(ds, "Company")
'maxRows = ds.Tables("Company").Rows.Count
'Dim cb As Odbc.OdbcCommandBuilder = New odbccoom(da)
Dim builder As OdbcCommandBuilder = New OdbcCommandBuilder(da)
ds.Tables("Company").Rows(inc).Item(0) = txtSlNo.Text
ds.Tables("Company").Rows(inc).Item(1) = txtCode.Text
ds.Tables("Company").Rows(inc).Item(2) = txtCompanyName.Text
ds.Tables("Company").Rows(inc).Item(3) = txtCompType.Text
ds.Tables("Company").Rows(inc).Item(4) = txtRegNo.Text
ds.Tables("Company").Rows(inc).Item(5) = CDate(dtpRegDate.Value)
ds.Tables("Company").Rows(inc).Item(6) = CDate(dtpRegExpDate.Value)
ds.Tables("Company").Rows(inc).Item(7) = txtComRegNo.Text
ds.Tables("Company").Rows(inc).Item(8) = txtActivity.Text
ds.Tables("Company").Rows(inc).Item(9) = txtOwner1.Text
ds.Tables("Company").Rows(inc).Item(10) = txtOwner2.Text
ds.Tables("Company").Rows(inc).Item(11) = txtOwner3.Text
ds.Tables("Company").Rows(inc).Item(12) = txtOwner4.Text
ds.Tables("Company").Rows(inc).Item(13) = txtOwner5.Text
ds.Tables("Company").Rows(inc).Item(14) = txtCapital.Text
MsgBox("Data updated")
MsgBox(ds.Tables("Company").Rows(inc).Item(2))
'ds.Tables("Company").GetChanges()
da.Update(ds, "Company")
MsgBox("COMPLETED")
End Sub
Private Sub NavigateRecords()
txtSlNo.Text = ds.Tables("Company").Rows(inc).Item(0)
txtCode.Text = ds.Tables("Company").Rows(inc).Item(1)
txtCompanyName.Text = ds.Tables("Company").Rows(inc).Item(2)
txtCompType.Text = ds.Tables("Company").Rows(inc).Item(3)
txtRegNo.Text = ds.Tables("Company").Rows(inc).Item(4)
dtpRegDate.Value = ds.Tables("Company").Rows(inc).Item(5)
dtpRegExpDate.Value = ds.Tables("Company").Rows(inc).Item(6)
txtComRegNo.Text = ds.Tables("Company").Rows(inc).Item(7)
txtActivity.Text = ds.Tables("Company").Rows(inc).Item(8)
txtOwner1.Text = ds.Tables("Company").Rows(inc).Item(9)
txtOwner2.Text = ds.Tables("Company").Rows(inc).Item(10)
txtOwner3.Text = ds.Tables("Company").Rows(inc).Item(11)
txtOwner4.Text = ds.Tables("Company").Rows(inc).Item(12)
txtOwner5.Text = ds.Tables("Company").Rows(inc).Item(13)
txtCapital.Text = ds.Tables("Company").Rows(inc).Item(14)
End Sub
Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
If inc <> maxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub cmdPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrevious.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("First Record")
End If
End Sub
Private Sub cmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
If inc <> maxRows - 1 Then
inc = maxRows - 1
NavigateRecords()
Else
MsgBox("Last Record")
End If
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
'inc = 0
'NavigateRecords()
MsgBox(inc)
'If inc <> -1 Then
Dim cb As New Odbc.OdbcCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("Company").NewRow()
dsNewRow.Item("SlNo") = txtSlNo.Text
dsNewRow.Item("Code") = txtCode.Text
dsNewRow.Item(2) = txtCompanyName.Text
dsNewRow.Item(3) = txtCompType.Text
dsNewRow.Item(4) = txtRegNo.Text
dsNewRow.Item(5) = CDate(dtpRegDate.Value)
dsNewRow.Item(6) = CDate(dtpRegExpDate.Value)
dsNewRow.Item(7) = txtComRegNo.Text
dsNewRow.Item(8) = txtActivity.Text
dsNewRow.Item(9) = txtOwner1.Text
dsNewRow.Item(10) = txtOwner2.Text
dsNewRow.Item(11) = txtOwner3.Text
dsNewRow.Item(12) = txtOwner4.Text
dsNewRow.Item(13) = txtOwner5.Text
dsNewRow.Item(14) = txtCapital.Text
ds.Tables("Company").Rows.Add(dsNewRow)
da.Update(ds, "Company")
MsgBox("New Record added to the Database")
ds.Reset()
'End If
End Sub
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim cb As New Odbc.OdbcCommandBuilder(da)
ds.Tables("Company").Rows(inc).Delete()
maxRows = maxRows - 1
inc = 0
NavigateRecords()
da.Update(ds, "Company")
End Sub
Private Sub Clear()
txtSlNo.Text = ""
txtCode.Text = ""
txtCompanyName.Text = ""
txtCompType.Text = ""
txtRegNo.Text = ""
txtComRegNo.Text = ""
txtActivity.Text = ""
txtOwner1.Text = ""
txtOwner2.Text = ""
txtOwner3.Text = ""
txtOwner4.Text = ""
txtOwner5.Text = ""
txtCapital.Text = ""
End Sub
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
|
|
|
|
|
binujeesman wrote: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
I'm guessing you haven't specified a primary key field in your table adapter/dataset.
binujeesman wrote: Also tell me hw can i use ggrid in Vb2005 for display and edition?
ggrid?
Why have you posted all the code from Form1? Surely you can narrow the problem down a bit?
|
|
|
|
|
but please tell me hw can i specify a primary key field in your table adapter/dataset.
its data grid what i meant.
pleaase help
|
|
|
|
|
A Primary Key is a field the uniquely identifies each record in a table. You have to add this field to your database tables, then update your application code accordingly.
If you don't know what a Primary Key is and its purpose, you really need to stop this project and learn relational database basics before you continue with this project. Google results for "database primary key[^]".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Hi,
How to incorporate English dictionary in VB 6.0
Actually i want avoid spelling mistek in text box or any componant.
Please Help::
Thank U
-- modified at 6:20 Thursday 2nd November, 2006
|
|
|
|
|
The best way to do this is to use a 3rd party component to supply the dictionary functionality. Google for "vb.net spellcheck textbox[^]".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
i have searched for a long time with no result, about this subject. I need to open a web page and give the values for the textfields(user,pass) by code.
With System.Diagnostics.Proccess.Start(filename, user, pass, domain) i take an win32 exception(I cant find why!)..I try to open a site which the username & password isnt remebered (http://www.managerzone.com/index.php?lang=en&changesport=soccer).
Also, I want to make handle events on this page...like the click of a button..
Can you help me?
Thanx in advance..
Kostas
|
|
|
|
|
The Process class will only launch the process (browser) in your case. You can't supply your site username and password to the Process class because it's expecting the credentials to launch the new process under. Kind of like "Run As". They have nothing to do with the website you're logging into.
Now, it's possible, however very unreliable, to launch the browser and have your code find the credentials window that pops up, and send the appropriate window messages to it to simluate the keystrokes to fill in those two blanks. But, THIS IS VERY UNRELIABLE.
Handle what events???
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
"Handle": I mean to make the click event of the button "loggin", for example!
Ok, thanx a lot for the advise!
|
|
|
|
|
How to extract file from e-mail automatically? and how to read the file? tq
SaM
|
|
|
|
|
You're going to have to explain how your getting this email first. Are you using Outlook, or some other mail package to do it? Did you implement your own STMP/POP3 clients? Did you use a 3rd party component to get the email?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thank you for your attention. Actually I want to use Yahoo! Mail or Outlook as a platform for extracting the file. Once I receive the e-mail, the program will read and extract the file automatically. Then, the file will be used for updating database(MapObjects+ArcView). What should I begin with?
SaM
|
|
|
|
|
First, you shouldn't be relying on Yahoo Mail, or any other application to do this for you. Yahoo Mail's user interface can, and will, change from time to time, rendering your code absolutely useless.
There are major issues with controlling the user interface of another application. I know, every newbie thinks it should be a piece of cake to do, but they simply do not understand how a UI works and therefore can't understand why it's so difficult to do. You simply do NOT do it if you want to write rock solid code.
If you're using VB.NET 2004, you can use the System.Web.Mail namespace to create your own email client, complete with the ability to unpack attachments. If your using 2005, then the System.Net.Mail[^] namespace has everything you need to download mail from an SMTP server and unpack attachments.
I HIGHLY recommend using the .NET Framework 2.0 to do this. It's email handling support is FAR better than the support offered by the .NET Framework 1.x.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
oh i see...ermm, do you have any script sample on how to use system.Net.Mail?
SaM
|
|
|
|
|
Hi..
Anyone could help me out in writing a vb.net windows application, which converts the given numbers to appropriate words(Ex.if 123 is entered,the output should be ONE HUNDRED AND TWENTY THREE)
Vijay Mesa
|
|
|
|
|
|
That sounds like a homework assignment to me... If it is, assume your lecturer is also reading these boards.
|
|
|
|
|
You must construct an algorithm to do this routine!
It will starts from the end of the integer..and reads one by one the numbers!
You must call two functions. First returns the number string (ex. 1 one), and second the "position" (if this number is 3rd from the end this is hundred).
It's too easy..
Kostas
|
|
|
|
|
Hi,
use this function...
Public Function Wording(ByVal Digits As Int16) As String
Dim Inword() As String = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"}
Dim Tenth() As String = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}
Dim MainWord As String
If Digits <= 20 Then
MainWord = Inword(Digits)
ElseIf Digits < 100 Then
MainWord = Tenth(Mid(Digits, 1, 1)) & " " & Inword(Mid(Digits, 2, 1))
End If
Wording = Trim(MainWord)
End Function
Public Function Convert(ByVal Indigit As String) As String
On Error GoTo err1
Dim word(8), Outword As String
Dim length, num2, i As Int16
Dim frac As Single
Dim flg As Boolean
frac = Val(Indigit) - Int(Val(Indigit))
If frac <> 0 Then
num2 = Mid(Str(frac), 3, 2)
If num2 <= 9 Then num2 = num2 * 10
If frac < 0.1 Then num2 = Mid(Str(frac), 3, 2)
word(0) = Wording(num2)
End If
Indigit = Int(Val(Indigit))
If Val(Indigit) <> 0 Then flg = True
length = Len(Indigit)
num2 = Val(Mid(Indigit, length, 1))
word(1) = Wording(num2)
num2 = Val(Mid(Indigit, length - 1, 2))
word(1) = Wording(num2)
num2 = Val(Mid(Indigit, length - 2, 1))
word(2) = Wording(num2)
num2 = Val(Mid(Indigit, length - 3, 1))
word(3) = Wording(num2)
num2 = Val(Mid(Indigit, length - 4, 2))
word(3) = Wording(num2)
num2 = Val(Mid(Indigit, length - 5, 1))
word(4) = Wording(num2)
num2 = Val(Mid(Indigit, length - 6, 2))
word(4) = Wording(num2)
num2 = Val(Mid(Indigit, length - 7, 1))
word(5) = Wording(num2)
num2 = Val(Mid(Indigit, length - 8, 2))
word(5) = Wording(num2)
err1:
For i = 5 To 0 Step -1
If word(i) <> "" Then
Select Case i
Case 0
If flg = False Then Outword = Outword + word(i) + " Paise" Else Outword = Outword + " And " + word(i) + " Paise"
Case 1
Outword = Outword + word(i)
Case 2
Outword = Outword + word(i) + " Hundred "
Case 3
Outword = Outword + word(i) + " Thousand "
Case 4
Outword = Outword + word(i) + " Lac "
Case 5
Outword = Outword + word(i) + " Crore "
End Select
End If
Next
If Outword = "" Then Outword = "Zero"
Convert = Outword
End Function
Public Function NumToWord(ByVal StrDigits As String) As String
Dim l, Pos As Int16
Dim a, b As String
Pos = InStr(StrDigits, ".")
If Pos = 0 Then a = StrDigits Else a = Mid(StrDigits, 1, Pos - 1)
l = Len(a)
If l > 7 Then
a = Mid(a, 1, l - 7)
b = Mid((StrDigits), l - 6)
NumToWord = Convert(a) & " Crore " & Convert(b)
Else
NumToWord = Convert(StrDigits)
End If
End Function
Thanks & Regards...
Amit
|
|
|
|
|
Your example is about twice the size it needs to be, but CONGRATULATIONS!!
You just did this guy's homework for him!! His prize?? A FAILING grade because the prof WILL know he didn't write the code! I hope you're happy...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi..
Anyone could help me out in writing a vb.net windows application, which converts the given numbers to appropriate words(Ex.if 123 is entered,the output should be ONE HUNDRED AND TWENTY THREE)
Vijay Mesa
|
|
|
|
|
Ahhh, the ubiquitous homework assignment. Just Google for "convert number to words" and you'll see thousands of examples.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I HAVE COMPLETED MY VB.NET WIN APPLICATION(consists of crystal report nd ado.net).
I HAVE ALSO GOT AN '.exe' FILE FOR IT.
NOW I NEED TO RUN THIS EXE AT ANOTHER PC
PLS SUGGEST THE REQUIREMENTS TO INSTALL IN THE OTHER PC
IS JUST DOTNET FRAME WORK SUFFICIENT
thanks in adv for ur reply
ramana mohan
|
|
|
|
|
Please don't SHOUT. It's annoying and rude.
From MSDN
In order for a .NET Framework application to run on a given computer, it must have the .NET Framework installed. Any .NET Framework application that uses ADO.NET to connect to databases requires MDAC 2.7. Many computers already have these components installed; however, to ensure an application will run, these components should be redistributed with your application.
dotnetfx.exe[^] (for .NET 1.1)
dotnetfx.exe[^] (for .NET 2.0)
MDAC 2.8[^]
|
|
|
|
|