|
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
|
|
|
|
|
hence code!
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.
|
|
|
|
|
Hello,
I have user control that has been placed on many tab pages. The tab control is not part of the user control. The user control consists of text boxes and combo boxes
The user can add new tabs and enter the data into it the user control and click save which is also part of the user control. However, if they decide to save on a previous tab and then click save it will save the contents of the text boxes and combo boxes that are on the last tab.
This is because the text boxes and combo boxes are taken from the last ones that are created.
How can I select another tab and click save, and save the contents of those text boxes and combo boxes on that tab?
my code for the save button in the user control.
Code:
<br />
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click <br />
Try <br />
Dim rowsAffected As Integer = Me.TA_IncidentTask1.UpdateTask(_incidentID, Me.cboSupportType.Text, Me.cboUsers.Text, Date.Now.ToLocalTime(), Date.Now, Me.txtTaskDetails.Text, Date.Now, Date.Now.ToLocalTime(), Me.cboStatus.Text, String.Empty, String.Empty, Me.txtCompletionNotes.Text, _taskID) <br />
Catch ex As Exception <br />
MessageBox.Show(ex.Message) <br />
End Try <br />
End Sub<br />
Many thanks for your help,
Steve
|
|
|
|
|
Hello,
I am using this code to loop through a tab control and get the name of the tab.
However it always fails with an index error on the last tab, even though it does get the name of the tab on the last one.
Can anyone see if there is anything wrong with the code below.
Code:
Dim i As Integer = 0
For i = 0 To Me.TabControl1.TabCount
taskID = Me.TabControl1.TabPages(i).Name
Next i
Many thanks,
Steve
|
|
|
|
|
Hi there,
Do the following:
Dim i As Integer = 0
For i = 0 To Me.TabControl1.TabCount - 1
taskID = Me.TabControl1.TabPages(i).Name
Next i
Regards, Werries
A programmer's life is good... or is it?? Ek dink nie so nie!
|
|
|
|
|
Hi there,
you need to use TabCount - 1 as the first index of the tabs is zero.
Alternatively, you can use this:
<br />
For Each t As TabPage In Me.TabControl1.TabPages<br />
taskID = t.Name.ToString()<br />
Next<br />
Hope this helps,
Daniel
|
|
|
|
|
|
Hi,
i have been playing with some code that creates Control array labels that display dates down in a column in a Windows Form, but i am having trouble with removing Control array labels if a date range changes.
How do i remove a Control Array Label? in the case where the quantity of labels required where to be reduced by the Control Form control selecting the start and end dates.
some of the code that i have been playing with is attached below.
************************************
************************************
' remove the day array. 'this part doesnt work in my case..
For pd As Integer = 0 To 12
Me.Controls.Remove(lblDayArray(pd))
Next
strDayRow = datAStartDate.ToString("dddd,dd MMMM")
'using the label DayArray create days in rows
For i As Integer = 0 To DayDiff
lblDayArray(i) = New Label
Me.Controls.Add(lblDayArray(i))
With lblDayArray(i)
.TextAlign = ContentAlignment.MiddleRight
.BorderStyle = BorderStyle.None
.Location = New Point(intDInitLocationX, intLocationY)
.Size = New Size(intDInitSizeL, intInitSizeH)
.Text = strDayRow
.Name = "lblDay(i)"
End With
intLocationY = intLocationY + intSpacingY 'increments to next day
datAStartDate = dpStartDateRange.Value
datAStartDate.AddDays(1)
Next
Microsoft Visual Basic .NET (2003) version 7.1.6030
Microsoft .NET Framework 1.1
Regards,
Colin
|
|
|
|
|
After finally getting somewhere with reading XML, I ran into a problem. I want to list all the feed titles in a listview, and then when I click on a title, I want to view the the "Description" tag corresponding to the selected item. What I am having trouble with is determining which item I have clicked so that I can display the corresponding description. Here is what I have now:
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim XMLDoc As XmlDocument
Dim NodeListTitle As XmlNodeList
Dim NodeListText As XmlNodeList
Dim XmlDocNode As XmlNode
XMLDoc = New XmlDocument()
XMLDoc.Load("C:\feed.xml")
NodeListTitle = XMLDoc.SelectNodes("/rss/channel/item/title")
NodeListText = XMLDoc.SelectNodes("/rss/channel/item/description")
'Determine what item is selected and display it's description
For Each XmlDocNode In NodeListText
PostBox.Text = XmlDocNode.InnerText
Next
End Sub
How should I go about getting the selected item and determining it's description tag? And is this the proper way to read an XML file? Thanks for the help!
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
hi there,
i have a problem with following coding. it is a coding of saving text file. and its saving the text file but when the file open in notepad then the all the lines merge together
eg. write 4 lines in textbox
12343
1232
222435
4343
and save
when open in notepad ,it look like this image
http://img213.imageshack.us/my.php?image=errorka4.jpg[^]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fName As String
Save.ShowDialog()
fName = Save.FileName
If Save.FileName <> "" Then
Dim fSave As New StreamWriter(fName)
fSave.WriteLine(Text1.Text)
fSave.Flush()
fSave.Close()
End If
End Sub
someone know what is the cause of it?
|
|
|
|
|
|
|
How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?
|
|
|
|
|
Just use the DateTime.Subtract function, like so:
Dim FirstDate As New DateTime(2007, 2, 2, 7, 0, 0)
Dim SecondDate As New DateTime(2001, 1, 1, 12, 0, 0)
Dim FinalDate As TimeSpan = FirstDate.Subtract(BDayNow)
Hope this helps!
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|