|
|
well its jst the simple addiing in data base...
here is the code for u..
check it out....and put yr table name wherever specified tablename and make required changes
<code>Imports System
Imports System.data.oledb
Inherits System.Windows.Forms.Form
public class form1
Dim da As New OleDbDataAdapter("select * from tablename", "provider=microsoft.jet.oledb.4.0;data source=|DataDirectory|\PCbank.mdb;")
Dim ds As New DataSet
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim i As Integer
Dim str As String
'under insert button
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Try
cn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=GIVE PATH of yr mdb file;")
cn.Open()
cmd = New OleDbCommand("insert into tablename(ID,surname,forename) values('" & (TextBox1.Text) & "','" & (TextBox2.Text) & "','" & (TextBox3.Text) & ")", cn)
i = cmd.ExecuteNonQuery()
MsgBox("record inserted")
Catch ex As Exception
End Try
cn.Close()</code>
|
|
|
|
|
you can use this code also:
Public Function Query(ByVal SQL As String, ByVal OLEDBCon As OleDb.OleDbConnection, ByRef DS As DataSet) As Integer
Dim DA As New OleDb.OleDbDataAdapter(SQL, OLEDBCon)
Query = DA.Fill(DS)
DA = Nothing
End Function
Public Function Execute(ByVal SQL As String, ByVal OLEDBCon As OleDb.OleDbConnection) As Integer
Dim com As New OleDb.OleDbCommand(SQL, OLEDBCon)
com.ExecuteNonQuery()
com = Nothing
End Function
this is your connection string:
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=sample.mdb")
code of your button save:
dim strInsert as string
try
strInsert="Insert into table1 (field1,fields2...) Values('" & txt1 & "','" & txt2 & "'...)"
con.open
Execute(strInsert,con)
MsgBox("Record Saved")
con.close
end try
my code is simple.
Don't block the drive way of all the newbies in programming. )
|
|
|
|
|
I have download copy paste avi file
how to run avi file in vb.net windows application
|
|
|
|
|
Just implement Windows Media Player into your app.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Hi
How can we capture the incoming net send message in vb.net?
Thanks
vijay
v
|
|
|
|
|
You can't really intercept them without writing your own packet sniffer ad reassembling the traffic yourself.
The other way to do it is to stop the Messenger service that comes with Windows and write your own replacement for it, taking over the TCP/IP port that it normally listens to.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I have an application that closes all IE windows that have "MKR" string in the address when the application closes. The problem is that explorer.exe is still listed in the processes. How do I get rid of the process when I close the application?
SR
|
|
|
|
|
You do know that explorer.exe is the process that give you your desktop, right? Why would you want to stop that?
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
The EXE you should look for is iexplore.exe.
Shreekar
|
|
|
|
|
Hi,
I am trying to execute the the function "RegSetKeySecurity" from advapi32.dll in VB Script.
for creating the object i am using wshAPIToolkitObject but i am getting the error...
"WScript.CreateObject: Could not locate automation class named "wshAPIToolkitObject.ucATO"
code :
Set oATO = WScript.CreateObject("wshAPIToolkitObject.ucATO")
lResult = oATO.CallAPI("advapi32.dll", "RegSetKeySecurity", hKey, SecurityInformation, pSecurityDescriptor )
please help me...do i need to have some dlls ?
or i need to register some dlls ?
|
|
|
|
|
It would appear that you either don't have this library installed (it's not part of Windows) or you do have it and it's not registered properly (use REGSVR32).
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
can anyone tell me how to connect to an access database and then add a feild to that database.
any help with this would be greatly appreciated as i literally don't have a clue how to do it.
|
|
|
|
|
what are you using ? adodb ? adodc ?
adding field/column ? why dont you make it directly in access ? or did you mean insert value of your table's fields ?
you can use sql - INSERT command to insert value of fields
and ALTER for add and drop column...
if you're using adodb.. here is the connect function
<br />
Function connect() As Boolean<br />
Dim strConnect As String<br />
connect = False<br />
On Error GoTo errHandler<br />
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpakar.mdb;"<br />
Set conn = New ADODB.Connection<br />
With conn<br />
.CursorLocation = adUseClient<br />
.Open strConnect<br />
End With<br />
connect = True<br />
Exit Function<br />
errHandler: Debug.Print "ERROR! error number: " & Err.Number & ", Description: " & Err.Description<br />
End Function<br />
dont forget to declare the conn , e.g
<br />
Public connVP As ADODB.Connection<br />
if you're using adodc, then just set the adodc's property.
sorry if this isn't the answer that you're looking for- i misunderstood it then..
Practicing
|
|
|
|
|
im using oledb. this is how i've tried to do it. it doesn't come up with any problems but it doesn't work.
Imports System.Data.OleDb
Public Class Cust
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim icount As Integer
Dim str As String
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=PCBank.mdb;")
cn.Open()
str = "insert into customer (CustomerID, CustomerSurname, CustomerForename) values ('tbID', 'tbSur', 'tbFor')"
'string stores the command and CInt is used to convert number to string
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
MessageBox.Show(icount)
'displays number of records inserted
Catch
End Try
cn.Close()
End Sub
End Class
|
|
|
|
|
sorry, did you succesfully connect to your db ?
i mean, where is your problem ? adding or connect ?
then what was the error message ?
Practicing
|
|
|
|
|
i dont know whether i have connected to the database or not, how can i tell?
i think i may of, there are no error messages . but when i add new record, no record gets added. i think that adding the record may be the problem?
|
|
|
|
|
Learn about the Try/Catch Statement.
This is how you would use it..
Try<br />
<br />
[bla bla bla]<br />
<br />
Catch ex As Exception<br />
Me.lbl.Text = ex.message<br />
End Try
The label called "lbl" should then display the error for you. Sorry this is vb.net code. I hope it's ok.
|
|
|
|
|
To check state of connection, you can use cn.ConnectionState or something like it.
The problem is you are eating up the error by not doing anything in the Catch block.
Do something like the other poster suggested to see if you have any error.
Also, your problem is this:
peteyshrew wrote: values ('tbID', 'tbSur', 'tbFor')"
You cannot insert a string for CustomerID (I am assuming).
What you need (maybe) is
CInt(tbID.text), tbSur.Text, tbFor.Text
A better method is to use stored procs to do this to avoid SQL injection attacks.
Hope this helps.
Shreekar
|
|
|
|
|
Imports System.Data.Oledb
Dim con as new Oledb.OledbConnection("Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=dbase.mdb")
NOTE: Put this code under the Public Class Form1
CODE OF BUTTON SAVE:
Dim objDataAdapter As New OleDb.OleDbDataAdapter
Dim objCommand As New OleDb.OleDbCommand
Dim objDataTable As New DataTable
Dim objDataSet As New DataSet
Dim objOleCon As New OleDb.OleDbConnection
Dim strInsert As String
Dim strSelect As String
Try
strSelect = "Select * from Table1"
strInsert = "Insert into Table1 (name,address) Values('" & tname.text & "','" & taddress.text & "')"
objOleCon = New OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; " & _
"Data Source=dbase.mdb")
objDataAdapter.SelectCommand = New OleDb.OleDbCommand(strInsert, objOleCon)
objDataAdapter.Fill(objDataSet)
objDataTable = objDataSet.Tables(0)
With objCommand
.Connection = objOleCon
.Connection.Open()
.CommandText = strInsert
.CommandType = CommandType.Text
.ExecuteNonQuery()
.Connection.Close()
End With
MsgBox("Record Saved")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Don't block the drive way of all the newbies in programming. )
|
|
|
|
|
Open Outlook Express with Attachments from VB.NET
When u attempt to Attach, please don't use the SendKeys.
How can I ?
|
|
|
|
|
Outlook Express doesn't expose an object model you can use. It's done through MAPI API calls.
There is no provision in RFC 2368 specifying any kind of support for adding attachments in a mailto: URI. Support for "attach", or some other keyword, is non-standard and completely up to the manufacturer of the mail package.
AFAICT, Outlook and Outlook Express don't support the attach keyword because of security concerns with viruses and trojans emailing themselves to the entire address book.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
when i click on NEW button i want all form controls such as textbox,radiobutton and checkbox will refresh
what i do for that (compulsary throgh loop)
|
|
|
|
|
Then use the Form.Controls property, see here [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
yes it is
but i want coding to use it
|
|
|
|