473,903 Members | 3,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I get the data using sql command???

What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?

Nov 20 '05 #1
5 2231
You should start learning ADO.NET, which is not just a quick reply to your
message.
"Gene" <eu*******@hotm ail.com> wrote in message
news:uS******** ******@TK2MSFTN GP09.phx.gbl...
What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?

Nov 20 '05 #2
Use the ExecuteNonQuery method of the command object. This will return the
rows affected.

Regards - OHM

Gene wrote:
What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?

Nov 20 '05 #3
THX for the reply,
I know how to do it by changing the text of DataBindings at the property
window,
but I want to know how to do it by coding,
THX!

"One Handed Man" <Bo****@Duck.ne t> 在郵件
news:bq******** **@hercules.bti nternet.com 中撰寫...
Use the ExecuteNonQuery method of the command object. This will return the
rows affected.

Regards - OHM

Gene wrote:
What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?


Nov 20 '05 #4
You have not been particularly specific about what you are trying to acheive

here is an example from one of my applications which uses an access
database:-

Dim cmd As New OleDbCommand

Dim uCmd As New OleDbCommand

' set connection string

con.ConnectionS tring = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""C:\Doc uments and Settings\Admini strator\My
Documents\" & _

"FamilyPlusFrie nds.mdb"";Jet OLEDB:Engine
Type=5;Provider =""Microsoft.Je t.OLEDB.4.0" & _

""";Jet OLEDB:System database=;Jet OLEDB:SFP=False ;persist security
info=False;Ext" & _

"ended Properties=;Mod e=Share Deny None;Jet OLEDB:Encrypt Database=False; Jet
OLED" & _

"B:Create System Database=False; Jet OLEDB:Don't Copy Locale on
Compact=False;J et " & _

"OLEDB:Comp act Without Replica Repair=False;Us er ID=Admin;Jet OLEDB:Global
Bulk T" & _

"ransaction s=1"

daEvents.TableM appings.AddRang e(New System.Data.Com mon.DataTableMa pping()
{New System.Data.Com mon.DataTableMa pping("Table", "Events", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("Action" , "Action"), New
System.Data.Com mon.DataColumnM apping("Comment s", "Comments") , New
System.Data.Com mon.DataColumnM apping("Date", "Date"), New
System.Data.Com mon.DataColumnM apping("EventTy pe", "EventType" ), New
System.Data.Com mon.DataColumnM apping("ID", "ID"), New
System.Data.Com mon.DataColumnM apping("PersonI ndex", "PersonIndex")} )})

daPeople.TableM appings.AddRang e(New System.Data.Com mon.DataTableMa pping()
{New System.Data.Com mon.DataTableMa pping("Table", "People", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("Address 1", "Address1") , New
System.Data.Com mon.DataColumnM apping("Address 2", "Address2") , New
System.Data.Com mon.DataColumnM apping("Address 3", "Address3") , New
System.Data.Com mon.DataColumnM apping("Address 4", "Address4") , New
System.Data.Com mon.DataColumnM apping("Country ", "Country"), New
System.Data.Com mon.DataColumnM apping("County" , "County"), New
System.Data.Com mon.DataColumnM apping("DOB", "DOB"), New
System.Data.Com mon.DataColumnM apping("Email", "Email"), New
System.Data.Com mon.DataColumnM apping("FirstNa me", "FirstName" ), New
System.Data.Com mon.DataColumnM apping("Home Phone", "Home Phone"), New
System.Data.Com mon.DataColumnM apping("LastNam e", "LastName") , New
System.Data.Com mon.DataColumnM apping("MiddleI nnitial", "MiddleInnitial "),
New System.Data.Com mon.DataColumnM apping("Mobile Fone", "Mobile Fone"), New
System.Data.Com mon.DataColumnM apping("Post Code", "Post Code"), New
System.Data.Com mon.DataColumnM apping("Town", "Town"), New
System.Data.Com mon.DataColumnM apping("ID", "ID")})})

'open connection

con.Open()

'Initialise People

SetPrimaryKeys( )

dgPeople.DataSo urce = tablePeople

peopleSelectCmd .CommandText = "SELECT ID,FirstName,La stName,DOB,[Mobile
Fone],[Home Phone],Email, Address1, Address2,Addres s3, Address4,Town, [Post
Code], County, Country,MiddleI nnitial FROM(People)ORD ER BY FirstName"

peopleSelectCmd .CommandType = CommandType.Tex t

peopleSelectCmd .Connection = con

daPeople.Select Command = peopleSelectCmd

daPeople.Fill(t ablePeople)

'Set up the People insert command

peopleInsertCmd .CommandType = CommandType.Tex t

peopleInsertCmd .CommandText = "INSERT INTO [People]([Address1], [Address2],
[Address3], [Address4], [Country], [County], [DOB], " & _

"[email], [FirstName], [Home Phone], [LastName], [MiddleInnitial], [Mobile
Fone], [Post Code]," & _

"[Town]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

peopleInsertCmd .Connection = con

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address1",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address1") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address2",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address2") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address3",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address3") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address4",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address4") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Country",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Country"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("County",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "County"))

peopleInsertCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("DOB",
System.Data.Ole Db.OleDbType.DB Date, 0, "DOB"))

peopleInsertCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Email",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Email"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("FirstName" ,
System.Data.Ole Db.OleDbType.Va rWChar, 20, "FirstName" ))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Home_Phone" ,
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Home Phone"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("LastName",
System.Data.Ole Db.OleDbType.Va rWChar, 20, "LastName") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("MiddleInnit ial",
System.Data.Ole Db.OleDbType.Va rWChar, 3, "MiddleInnitial "))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Mobile_Fone ",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Mobile Fone"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Post_Code" ,
System.Data.Ole Db.OleDbType.Va rWChar, 10, "Post Code"))

peopleInsertCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Town",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Town"))

'

daPeople.Insert Command = peopleInsertCmd

'setup People Update Command

peopleUpdateCmd .CommandText = "UPDATE People SET Address1 = ?, Address2 = ?,
Address3 = ?, Address4 = ?, Country" & _

" = ?, County = ?, DOB = ?, Email = ?, FirstName = ?, [Home Phone] = ?,
LastName " & _

"= ?, MiddleInnitial = ?, [Mobile Fone] = ?, [Post Code] = ?, Town = ? WHERE
(ID " & _

"= ?) AND (Address1 = ?) AND (Address2 = ?) AND (Address3 = ?) AND (Address4
= ?)" & _

" AND (Country = ?) AND (County = ?) AND (DOB = ?) AND (Email = ? OR ? IS
NULL AN" & _

"D Email IS NULL) AND (FirstName = ?) AND ([Home Phone] = ?) AND (LastName =
?) A" & _

"ND (MiddleInnitial = ? OR ? IS NULL AND MiddleInnitial IS NULL) AND
([Mobile Fon" & _

"e] = ? OR ? IS NULL AND [Mobile Fone] IS NULL) AND ([Post Code] = ?) AND
(Town =" & _

" ?)"

peopleUpdateCmd .Connection = con

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address1",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address1") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address2",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address2") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address3",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address3") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address4",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address4") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Country",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Country"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("County",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "County"))

peopleUpdateCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("DOB",
System.Data.Ole Db.OleDbType.DB Date, 0, "DOB"))

peopleUpdateCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Email",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Email"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("FirstName" ,
System.Data.Ole Db.OleDbType.Va rWChar, 20, "FirstName" ))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Home_Phone" ,
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Home Phone"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("LastName",
System.Data.Ole Db.OleDbType.Va rWChar, 20, "LastName") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("MiddleInnit ial",
System.Data.Ole Db.OleDbType.Va rWChar, 3, "MiddleInnitial "))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Mobile_Fone ",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Mobile Fone"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Post_Code" ,
System.Data.Ole Db.OleDbType.Va rWChar, 10, "Post Code"))

peopleUpdateCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Town",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Town"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_ID ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"ID", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address1", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress2",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address2", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress3",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address3", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress4",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address4", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co untry",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Country", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co unty",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byt),
"County", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_DO B",
System.Data.Ole Db.OleDbType.DB Date, 0, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Fi rstName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"FirstName" , System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ho me_Phone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Home Phone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_La stName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"LastName", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial1",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Po st_Code",
System.Data.Ole Db.OleDbType.Va rWChar, 10,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Post Code", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_To wn",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Town", System.Data.Dat aRowVersion.Ori ginal, Nothing))

daPeople.Update Command = peopleUpdateCmd



'Setup People Delete Command

peopleDeleteCmd .CommandText = "DELETE FROM People WHERE ([ID] = ?) AND
(Address1 = ?) AND (Address2 = ?) AND (Addr" & _

"ess3 = ?) AND (Address4 = ?) AND (Country = ?) AND (County = ?) AND (DOB =
?) AN" & _

"D (Email = ? OR ? IS NULL AND Email IS NULL) AND (FirstName = ?) AND ([Home
Phon" & _

"e] = ?) AND (LastName = ?) AND (MiddleInnitial = ? OR ? IS NULL AND
MiddleInniti" & _

"al IS NULL) AND ([Mobile Fone] = ? OR ? IS NULL AND [Mobile Fone] IS NULL)
AND (" & _

"[Post Code] = ?) AND (Town = ?)"

peopleDeleteCmd .Connection = con

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_ID ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"ID", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address1", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress2",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address2", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress3",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address3", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress4",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Address4", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co untry",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Country", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co unty",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"County", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_DO B",
System.Data.Ole Db.OleDbType.DB Date, 0, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Fi rstName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"FirstName" , System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ho me_Phone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Home Phone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_La stName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"LastName", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial1",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Po st_Code",
System.Data.Ole Db.OleDbType.Va rWChar, 10,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Post Code", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_To wn",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte),
"Town", System.Data.Dat aRowVersion.Ori ginal, Nothing))

'

daPeople.Delete Command = peopleDeleteCmd

'Initialise Events

Try

tableEvents.Cle ar()

dgEvents.DataSo urce = tableEvents

eventsSelectCmd .CommandType = CommandType.Tex t

eventsSelectCmd .CommandText = "SELECT
[PersonIndex],[EventType],[Date],[Comments],[Action],[ID] FROM ([Events])
WHERE PersonIndex=? "

eventsSelectCmd .Connection = con

eventsSelectCmd .Parameters.Add ("@ID",
dgPeople.Item(d gPeople.Current RowIndex, 0))

daEvents.Select Command = eventsSelectCmd

daEvents.Fill(t ableEvents)

Catch ex As OleDbException

MessageBox.Show (ex.Message)

Catch ex As ArgumentExcepti on

MessageBox.Show (ex.tostring)

End Try


Gene wrote:
THX for the reply,
I know how to do it by changing the text of DataBindings at the
property window,
but I want to know how to do it by coding,
THX!

"One Handed Man" <Bo****@Duck.ne t> 在郵件
news:bq******** **@hercules.bti nternet.com 中撰寫...
Use the ExecuteNonQuery method of the command object. This will
return the rows affected.

Regards - OHM

Gene wrote:
What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?

Nov 20 '05 #5
THX for your help

"One Handed Man" <Bo****@Duck.ne t> 在郵件
news:bq******** **@hercules.bti nternet.com 中撰寫...
You have not been particularly specific about what you are trying to acheive
here is an example from one of my applications which uses an access
database:-

Dim cmd As New OleDbCommand

Dim uCmd As New OleDbCommand

' set connection string

con.ConnectionS tring = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""C:\Doc uments and Settings\Admini strator\My
Documents\" & _

"FamilyPlusFrie nds.mdb"";Jet OLEDB:Engine
Type=5;Provider =""Microsoft.Je t.OLEDB.4.0" & _

""";Jet OLEDB:System database=;Jet OLEDB:SFP=False ;persist security
info=False;Ext" & _

"ended Properties=;Mod e=Share Deny None;Jet OLEDB:Encrypt Database=False; Jet OLED" & _

"B:Create System Database=False; Jet OLEDB:Don't Copy Locale on
Compact=False;J et " & _

"OLEDB:Comp act Without Replica Repair=False;Us er ID=Admin;Jet OLEDB:Global
Bulk T" & _

"ransaction s=1"

daEvents.TableM appings.AddRang e(New System.Data.Com mon.DataTableMa pping()
{New System.Data.Com mon.DataTableMa pping("Table", "Events", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("Action" , "Action"), New
System.Data.Com mon.DataColumnM apping("Comment s", "Comments") , New
System.Data.Com mon.DataColumnM apping("Date", "Date"), New
System.Data.Com mon.DataColumnM apping("EventTy pe", "EventType" ), New
System.Data.Com mon.DataColumnM apping("ID", "ID"), New
System.Data.Com mon.DataColumnM apping("PersonI ndex", "PersonIndex")} )})

daPeople.TableM appings.AddRang e(New System.Data.Com mon.DataTableMa pping()
{New System.Data.Com mon.DataTableMa pping("Table", "People", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("Address 1", "Address1") , New
System.Data.Com mon.DataColumnM apping("Address 2", "Address2") , New
System.Data.Com mon.DataColumnM apping("Address 3", "Address3") , New
System.Data.Com mon.DataColumnM apping("Address 4", "Address4") , New
System.Data.Com mon.DataColumnM apping("Country ", "Country"), New
System.Data.Com mon.DataColumnM apping("County" , "County"), New
System.Data.Com mon.DataColumnM apping("DOB", "DOB"), New
System.Data.Com mon.DataColumnM apping("Email", "Email"), New
System.Data.Com mon.DataColumnM apping("FirstNa me", "FirstName" ), New
System.Data.Com mon.DataColumnM apping("Home Phone", "Home Phone"), New
System.Data.Com mon.DataColumnM apping("LastNam e", "LastName") , New
System.Data.Com mon.DataColumnM apping("MiddleI nnitial", "MiddleInnitial "),
New System.Data.Com mon.DataColumnM apping("Mobile Fone", "Mobile Fone"), New System.Data.Com mon.DataColumnM apping("Post Code", "Post Code"), New
System.Data.Com mon.DataColumnM apping("Town", "Town"), New
System.Data.Com mon.DataColumnM apping("ID", "ID")})})

'open connection

con.Open()

'Initialise People

SetPrimaryKeys( )

dgPeople.DataSo urce = tablePeople

peopleSelectCmd .CommandText = "SELECT ID,FirstName,La stName,DOB,[Mobile
Fone],[Home Phone],Email, Address1, Address2,Addres s3, Address4,Town, [Post Code], County, Country,MiddleI nnitial FROM(People)ORD ER BY FirstName"

peopleSelectCmd .CommandType = CommandType.Tex t

peopleSelectCmd .Connection = con

daPeople.Select Command = peopleSelectCmd

daPeople.Fill(t ablePeople)

'Set up the People insert command

peopleInsertCmd .CommandType = CommandType.Tex t

peopleInsertCmd .CommandText = "INSERT INTO [People]([Address1], [Address2], [Address3], [Address4], [Country], [County], [DOB], " & _

"[email], [FirstName], [Home Phone], [LastName], [MiddleInnitial], [Mobile
Fone], [Post Code]," & _

"[Town]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

peopleInsertCmd .Connection = con

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address1",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address1") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address2",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address2") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address3",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address3") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address4",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address4") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Country",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Country"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("County",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "County"))

peopleInsertCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("DOB",
System.Data.Ole Db.OleDbType.DB Date, 0, "DOB"))

peopleInsertCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Email", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Email"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("FirstName" ,
System.Data.Ole Db.OleDbType.Va rWChar, 20, "FirstName" ))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Home_Phone" ,
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Home Phone"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("LastName",
System.Data.Ole Db.OleDbType.Va rWChar, 20, "LastName") )

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("MiddleInnit ial",
System.Data.Ole Db.OleDbType.Va rWChar, 3, "MiddleInnitial "))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Mobile_Fone ",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Mobile Fone"))

peopleInsertCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Post_Code" ,
System.Data.Ole Db.OleDbType.Va rWChar, 10, "Post Code"))

peopleInsertCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Town", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Town"))

'

daPeople.Insert Command = peopleInsertCmd

'setup People Update Command

peopleUpdateCmd .CommandText = "UPDATE People SET Address1 = ?, Address2 = ?, Address3 = ?, Address4 = ?, Country" & _

" = ?, County = ?, DOB = ?, Email = ?, FirstName = ?, [Home Phone] = ?,
LastName " & _

"= ?, MiddleInnitial = ?, [Mobile Fone] = ?, [Post Code] = ?, Town = ? WHERE (ID " & _

"= ?) AND (Address1 = ?) AND (Address2 = ?) AND (Address3 = ?) AND (Address4 = ?)" & _

" AND (Country = ?) AND (County = ?) AND (DOB = ?) AND (Email = ? OR ? IS
NULL AN" & _

"D Email IS NULL) AND (FirstName = ?) AND ([Home Phone] = ?) AND (LastName = ?) A" & _

"ND (MiddleInnitial = ? OR ? IS NULL AND MiddleInnitial IS NULL) AND
([Mobile Fon" & _

"e] = ? OR ? IS NULL AND [Mobile Fone] IS NULL) AND ([Post Code] = ?) AND
(Town =" & _

" ?)"

peopleUpdateCmd .Connection = con

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address1",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address1") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address2",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address2") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address3",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address3") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Address4",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Address4") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Country",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Country"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("County",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "County"))

peopleUpdateCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("DOB",
System.Data.Ole Db.OleDbType.DB Date, 0, "DOB"))

peopleUpdateCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Email", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Email"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("FirstName" ,
System.Data.Ole Db.OleDbType.Va rWChar, 20, "FirstName" ))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Home_Phone" ,
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Home Phone"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("LastName",
System.Data.Ole Db.OleDbType.Va rWChar, 20, "LastName") )

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("MiddleInnit ial",
System.Data.Ole Db.OleDbType.Va rWChar, 3, "MiddleInnitial "))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Mobile_Fone ",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Mobile Fone"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Post_Code" ,
System.Data.Ole Db.OleDbType.Va rWChar, 10, "Post Code"))

peopleUpdateCmd .Parameters.Add (New System.Data.Ole Db.OleDbParamet er("Town", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Town"))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_ID ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address1", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress2",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address2", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress3",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address3", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress4",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address4", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co untry",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Country", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co unty",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirectin. Input, False, CType(0, Byte), CType(0, Byte), "County", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_DO B",
System.Data.Ole Db.OleDbType.DB Date, 0, System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Fi rstName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "FirstName" , System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ho me_Phone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Home Phone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_La stName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "LastName", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial1",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Po st_Code",
System.Data.Ole Db.OleDbType.Va rWChar, 10,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Post Code", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleUpdateCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_To wn",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Town", System.Data.Dat aRowVersion.Ori ginal, Nothing))

daPeople.Update Command = peopleUpdateCmd



'Setup People Delete Command

peopleDeleteCmd .CommandText = "DELETE FROM People WHERE ([ID] = ?) AND
(Address1 = ?) AND (Address2 = ?) AND (Addr" & _

"ess3 = ?) AND (Address4 = ?) AND (Country = ?) AND (County = ?) AND (DOB = ?) AN" & _

"D (Email = ? OR ? IS NULL AND Email IS NULL) AND (FirstName = ?) AND ([Home Phon" & _

"e] = ?) AND (LastName = ?) AND (MiddleInnitial = ? OR ? IS NULL AND
MiddleInniti" & _

"al IS NULL) AND ([Mobile Fone] = ? OR ? IS NULL AND [Mobile Fone] IS NULL) AND (" & _

"[Post Code] = ?) AND (Town = ?)"

peopleDeleteCmd .Connection = con

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_ID ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address1", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress2",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address2", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress3",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address3", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ad dress4",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Address4", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co untry",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Country", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Co unty",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "County", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_DO B",
System.Data.Ole Db.OleDbType.DB Date, 0, System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Em ail1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Fi rstName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "FirstName" , System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Ho me_Phone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Home Phone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_La stName",
System.Data.Ole Db.OleDbType.Va rWChar, 20,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "LastName", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mi ddleInnitial1",
System.Data.Ole Db.OleDbType.Va rWChar, 3,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial ", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Mo bile_Fone1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_Po st_Code",
System.Data.Ole Db.OleDbType.Va rWChar, 10,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Post Code", System.Data.Dat aRowVersion.Ori ginal, Nothing))

peopleDeleteCmd .Parameters.Add (New
System.Data.Ole Db.OleDbParamet er("Original_To wn",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, False, CType(0, Byte), CType(0, Byte), "Town", System.Data.Dat aRowVersion.Ori ginal, Nothing))

'

daPeople.Delete Command = peopleDeleteCmd

'Initialise Events

Try

tableEvents.Cle ar()

dgEvents.DataSo urce = tableEvents

eventsSelectCmd .CommandType = CommandType.Tex t

eventsSelectCmd .CommandText = "SELECT
[PersonIndex],[EventType],[Date],[Comments],[Action],[ID] FROM ([Events])
WHERE PersonIndex=? "

eventsSelectCmd .Connection = con

eventsSelectCmd .Parameters.Add ("@ID",
dgPeople.Item(d gPeople.Current RowIndex, 0))

daEvents.Select Command = eventsSelectCmd

daEvents.Fill(t ableEvents)

Catch ex As OleDbException

MessageBox.Show (ex.Message)

Catch ex As ArgumentExcepti on

MessageBox.Show (ex.tostring)

End Try


Gene wrote:
THX for the reply,
I know how to do it by changing the text of DataBindings at the
property window,
but I want to know how to do it by coding,
THX!

"One Handed Man" <Bo****@Duck.ne t> 在郵件
news:bq******** **@hercules.bti nternet.com 中撰寫...
Use the ExecuteNonQuery method of the command object. This will
return the rows affected.

Regards - OHM

Gene wrote:
What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6693
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to be able to place the PHP file on the server, and I guess you probably can't do that either. Talk about catch 22... The only other way I can think of is to install MySQL on a machine you control, then import the data there using the method I...
1
9208
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this will work for 9i and even 10g ) No one had what I needed, so I wrote it myself. I Rule. This code isn't going for efficiency, and isn't trying to be dynamic. It doesn't create the table structure in Oracle, that's up to you. (I
3
3141
by: markaelkins | last post by:
I want to create a simple user interface to collect the following data and store the data in a SQL database. Could someone please help me get started? Data to collect from user interface and store in database: tDateS (trade date sell) tDateB (trade date buy) contracts (number of contracts) strike (stike price) sValue (sell value) bValue (buy value)
1
6908
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by itself (asp.net recycled?); it also can be solved by restarting IIS. Any ideas what cause(s) this to happen? System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr) at...
8
1906
by: rriness | last post by:
I'm getting an inconsistent failure when trying to save data in ADO.Net. I'm using an Access database with a simple query - SELECT StudentID, FirstName, LastName FROM Students - and have no other users in the database. I keep getting the message 'Operation must use an updateable query.' Process seems to work on some PC's, not others. Is there a difference in .Net framework versions? Or some other
3
2767
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to phpinfo, the "mysql api client is ver. 4.0.25" - I have no idea how this relates, if at all, to the mysql engine's version. background:
9
2777
by: Alex Buell | last post by:
I have a small text file which consist of the following data: ]] And the code I've written is as follows: ]] The trouble is, I can't work out why it goes into an infinite loop reading the information from the text file! Can anyone enlighten me as to what I am doing wrong?
6
8170
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a website...
7
8234
by: RB0135 | last post by:
Hi All, I have some Windows BMP, 1BPP, monochrome files that I need to get the raw data from to load a graphics buffer on a Roll Printer (which I know can be done). Lets forget about the Roll Printer in this equation as I am not sure I am getting the correct "raw" image from the file. However, when I print what I think is the raw data, I get the image size, but the information within the image looks nothing like it should be, and...
0
9999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10983
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10500
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8048
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7206
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3324
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.