|
Dim DBPath As String
Dim ADOXcat As New ADOX.Catalog
Dim sCreateString As String
DBPath = System.Windows.Forms.Application.StartupPath()
sCreateString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;" 'for Access 2007
Try 'Create DB
ADOXcat.Create(sCreateString)
Catch ex As System.Runtime.InteropServices.COMException
'create DB failed
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Failed to create database")
Finally
ADOXcat = Nothing
End Try
Dim ADOXtable As New ADOX.Table(), _
ADOXindex As New ADOX.Index(), _
Con As New ADODB.Connection()
Try 'connect and insert tables
Con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;") 'for 2007
MsgBox(Con.Errors().Count.ToString()) 'Displays 0 Errors
MsgBox(Con.State.ToString()) 'Displays 1 representing an open connection
'Open the Catalog
ADOXcat.ActiveConnection = Con 'Object reference not set to an instance of an object.
I know this error usally gets generated when using a null object but if I receive no errors from opening the connection then 'Con' shouldnt be null right? Any help on this is greatly appreshated.
|
|
|
|
|
Your con is fine, it is the ADOXCat that is not instantiated!
Quote from Great Outdoors:
its a confident traveller who farts in India
|
|
|
|
|
--> which symmetric algorithm is efficient to encrypt video file and why?
--> how can i compress video file in dotNet environment?
J A Nasir K
|
|
|
|
|
1 - they all are, to one degree or another. XVid and DivX are good, but so is MPG.
2 - by using DirectX
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i try to add datepicker to datagrid but i can see it, way?
Private Sub dg2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dg2.MouseDown
dtp.Dock = DockStyle.Fill
dtp.Cursor = Cursors.Arrow
dtp.SendToBack()
hitTestGrid = dg2.HitTest(e.X, e.Y)
If hitTestGrid.Column = 5 Then
datagridtextBox.TextBox.Controls.Add(dtp)
dtp.BringToFront()
End If
datagridtextBox.TextBox.BackColor = Color.Black
End Sub
|
|
|
|
|
liat1234 wrote: datagridtextBox.TextBox.Controls.Add(dtp)
You can't add a datetimepicker to a textbox. You can't add any controls to a textbox, unless you are using WPF
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i try to update my data base but i get this error message
"the update command effected 0 of the expected 1 records"
the insertcommand is ok
my code is
Private Sub btnUPDT_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUPDT.Click
'--------------------------------
'INSERT NEW ROWS
'--------------------------------
cmd.InsertCommand = New OleDbCommand()
Dim pCust_name1 As New OleDbParameter("@name1", OleDbType.VarChar)
pCust_name1.SourceColumn = "name"
Dim pCust_pass1 As New OleDbParameter("@pass1", OleDbType.VarChar)
pCust_pass1.SourceColumn = "pass"
Dim pCust_meried1 As New OleDbParameter("@meried1", OleDbType.Boolean)
pCust_meried1.SourceColumn = "meried"
Dim pCust_city1 As New OleDbParameter("@city1", OleDbType.VarChar)
pCust_city1.SourceColumn = "city"
Dim pCust_borndate1 As New OleDbParameter("@borndate1", OleDbType.Date)
pCust_borndate1.SourceColumn = "borndate"
cmd.InsertCommand.Parameters.Add(pCust_name1)
cmd.InsertCommand.Parameters.Add(pCust_pass1)
cmd.InsertCommand.Parameters.Add(pCust_meried1)
cmd.InsertCommand.Parameters.Add(pCust_city1)
cmd.InsertCommand.Parameters.Add(pCust_borndate1)
cmd.InsertCommand.Connection = Conn
cmd.InsertCommand.CommandText = "INSERT INTO users " & _
"(name, pass, meried, city, borndate)" & _
"VALUES (@name1, @pass1, @meried, @city, @borndate)"
'------------------------------------------
'UPDATE ROW
'------------------------------------
cmd.UpdateCommand = New OleDbCommand()
Dim pCust_id As New OleDbParameter("@id", OleDbType.Integer)
pCust_id.SourceColumn = "id"
Dim pCust_name As New OleDbParameter("@name", OleDbType.VarChar)
pCust_name.SourceColumn = "name"
Dim pCust_pass As New OleDbParameter("@pass", OleDbType.VarChar)
pCust_pass.SourceColumn = "pass"
Dim pCust_meried As New OleDbParameter("@meried", OleDbType.Boolean)
pCust_meried.SourceColumn = "meried"
Dim pCust_city As New OleDbParameter("@city", OleDbType.VarChar)
pCust_city.SourceColumn = "city"
Dim pCust_borndate As New OleDbParameter("@borndate", OleDbType.VarChar)
pCust_borndate.SourceColumn = "borndate"
cmd.UpdateCommand.Parameters.Add(pCust_id)
cmd.UpdateCommand.Parameters.Add(pCust_name)
cmd.UpdateCommand.Parameters.Add(pCust_pass)
cmd.UpdateCommand.Parameters.Add(pCust_meried)
cmd.UpdateCommand.Parameters.Add(pCust_city)
cmd.UpdateCommand.Parameters.Add(pCust_borndate)
cmd.UpdateCommand.Connection = Conn
cmd.UpdateCommand.CommandText = " UPDATE users SET [name]= @name, [pass]= @pass, [meried]=@meried WHERE [id] =@id"
cmd.Update(ds1, "users")
MsgBox("update table ended")
End Sub
|
|
|
|
|
hi
your code is fine, you have made it complicate you. in this cases, please use a Procedure to insert a new record into the table to avoid Sql injection. and i dont know how you gonna update a datagrid like that. check this article on how to update a datagrid.
.
http://www.codeproject.com/useritems/N-Tier_Application_VB.asp[^]
Hope i helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
i wrote this code but always row index 0 is deleted
where i wrong????
Private Sub btnDel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Dim i As Integer
Dim usrId As String
ds1.GetChanges()
i = dg2.CurrentRowIndex()
usrId = dg2.Item(i, 0)
'delete from dataset
ds1.Tables(0).Rows(i).Delete()
cmd.DeleteCommand = New OleDbCommand()
cmd.DeleteCommand.Connection = Conn
cmd.DeleteCommand.CommandText = "delete * from users where id =" & usrId
'delete from database
cmd.Update(ds1, "users")
End Sub
liat
|
|
|
|
|
liat1234 wrote: i = dg2.CurrentRowIndex()
The current row index must be 0. If you want to delete a different row, select the row you want to delete by setting this property.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hi,
You may try to do this in the following manner.
Dim con As SqlConnection
Dim adap As SqlDataAdapter
Dim ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
binddata()
End Sub
Dim i As Integer
Dim s As String
Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
i = DataGrid1.CurrentRowIndex
s = DataGrid1.Item(i, 0)
End Sub
Sub binddata()
Try
con = New SqlConnection("server=200.100.100.139;user id=sa;pwd=hello;database=pubs;")
con.Open()
adap = New SqlDataAdapter("select * from employee", con)
adap.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection("server=200.100.100.139;user id=sa;pwd=hello;database=pubs;")
con.Open()
Dim cmd As New SqlCommand
cmd = New SqlCommand("delete from employee where emp_id='" & s & "'", con)
cmd.ExecuteNonQuery()
binddata()
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
End Sub
I hope this helps.
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hello every one...
I am developing a application in vb.net, i want the text in mask box to be selected when a user enters in it..
I was able to do the same with Vb6, i am not able to do in VB.net 2005 Express..
Is the same also possible with text box??
Regards
Nishkarsh
|
|
|
|
|
Yes, you can set the selection index and selection length of the textbox when the focus/enter event occurs
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi all
Plz give me a sample about read a barcode from scanner and save it to database.
Thanks
|
|
|
|
|
Do you have a barcode scanner ? If not, how will you use the code ? If so, have you read the manual that came with it, explaining how to interact with it in code ?
We don't do people's work here, we help people who have tried and are stuck. It sounds to me like you want to do two well defined things, both of them easily answered with resources you should have ( a scanner with a manual and google )
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Barcode scanners typically emulate keyboard input... and are not a seperate device! They plug right into the Keyboard jack in parallel!
I designed and built a complete Point-of-Sale system in VBA for Access.
|
|
|
|
|
Hi,
In VB.Net how can I declare an varible in one line and instantiate it in another?
such this that can do in C#:
DataTable dt;
dt = new DataTable();
Best wishes
|
|
|
|
|
yes if it is a local variable it goes something like this. If not just replace dim with private or public or whatever.
dim dt as DataTable<br />
dt = new DataTable()
|
|
|
|
|
While you have your answer, you shouldn't do this. Always assign a variable a default value the moment you create it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
woul u pls subscribe us sample code of hospital management information system.we'll be very garateful.thanks
with regards
|
|
|
|
|
The depressing thing is that I can't tell if you're joking. If this is homework, you need to do your own homework. If this is paid work, can you tell me the hospital, so I can make sure never to go there ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: If this is paid work, can you tell me the hospital, so I can make sure never to go there ?
Same here, I'll make sure I stay away from there.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
trimp wrote: pls subscribe us sample code of hospital management information system
Nope. Do your own work.
"You posted your question here, indicating that you're so thick you couldn't find the VB Forum if it was licking your bung hole." - John Simmons / outlaw programmer
|
|
|
|
|
Wow. Normally I ignore posts asking people to do whole subsystems for them. An entire hospital management information system? That takes the cake as craziest request so far :P
|
|
|
|
|
Can someone tell me whats wrong with this code: Im getting the following error from vbscript runtime:
Line: 18
Char 1
Error: Object required:"
Code: 800A01A8
This is line 18
* If Lcase(Right(objFile.Name,3))="sln" Then *
-Code-
Option Explicit
'==========================Variable declaration & Initialization================================
Dim objFSO, objFolder, objSubFolder, objSubFile, objFile, objShell, colFiles, colFolders, strFolder
strFolder = "C:\Program Files\Visual Studio 2005 SDK"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
Set objShell = CreateObject("WScript.Shell")
'===============================================================================================
For Each objFile in colFiles
Set objFile = objFSO.GetFile(strFolder & "\" & File.Name)
Next
If Lcase(Right(objFile.Name,3))="sln" Then
objShell.Run "devenv /build" & objFile
End If
ScanSubFolders(objFolder)
Sub ScanSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
Set colFiles = objSubFolder.Files
For Each objFile in colfiles
If lcase(Right(objFile.Name,3)) = "sln" Then
objShell.Run "devenv /build" & objFile
End If
Next
ScanSubFolders(objSubFolder)
Next
|
|
|
|