By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,586 Members | 623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,586 IT Pros & Developers. It's quick & easy.

Can I get the data using sql command???

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
You should start learning ADO.NET, which is not just a quick reply to your
message.
"Gene" <eu*******@hotmail.com> wrote in message
news:uS**************@TK2MSFTNGP09.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

P: n/a
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

P: n/a
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.net> 在郵件
news:bq**********@hercules.btinternet.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

P: n/a
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.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""C:\Documents and Settings\Administrator\My
Documents\" & _

"FamilyPlusFriends.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0" & _

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

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

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

"OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global
Bulk T" & _

"ransactions=1"

daEvents.TableMappings.AddRange(New System.Data.Common.DataTableMapping()
{New System.Data.Common.DataTableMapping("Table", "Events", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("Action", "Action"), New
System.Data.Common.DataColumnMapping("Comments", "Comments"), New
System.Data.Common.DataColumnMapping("Date", "Date"), New
System.Data.Common.DataColumnMapping("EventType", "EventType"), New
System.Data.Common.DataColumnMapping("ID", "ID"), New
System.Data.Common.DataColumnMapping("PersonIndex" , "PersonIndex")})})

daPeople.TableMappings.AddRange(New System.Data.Common.DataTableMapping()
{New System.Data.Common.DataTableMapping("Table", "People", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("Address1", "Address1"), New
System.Data.Common.DataColumnMapping("Address2", "Address2"), New
System.Data.Common.DataColumnMapping("Address3", "Address3"), New
System.Data.Common.DataColumnMapping("Address4", "Address4"), New
System.Data.Common.DataColumnMapping("Country", "Country"), New
System.Data.Common.DataColumnMapping("County", "County"), New
System.Data.Common.DataColumnMapping("DOB", "DOB"), New
System.Data.Common.DataColumnMapping("Email", "Email"), New
System.Data.Common.DataColumnMapping("FirstName", "FirstName"), New
System.Data.Common.DataColumnMapping("Home Phone", "Home Phone"), New
System.Data.Common.DataColumnMapping("LastName", "LastName"), New
System.Data.Common.DataColumnMapping("MiddleInniti al", "MiddleInnitial"),
New System.Data.Common.DataColumnMapping("Mobile Fone", "Mobile Fone"), New
System.Data.Common.DataColumnMapping("Post Code", "Post Code"), New
System.Data.Common.DataColumnMapping("Town", "Town"), New
System.Data.Common.DataColumnMapping("ID", "ID")})})

'open connection

con.Open()

'Initialise People

SetPrimaryKeys()

dgPeople.DataSource = tablePeople

peopleSelectCmd.CommandText = "SELECT ID,FirstName,LastName,DOB,[Mobile
Fone],[Home Phone],Email, Address1, Address2,Address3, Address4,Town, [Post
Code], County, Country,MiddleInnitial FROM(People)ORDER BY FirstName"

peopleSelectCmd.CommandType = CommandType.Text

peopleSelectCmd.Connection = con

daPeople.SelectCommand = peopleSelectCmd

daPeople.Fill(tablePeople)

'Set up the People insert command

peopleInsertCmd.CommandType = CommandType.Text

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.OleDb.OleDbParameter("Address1",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address1"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address2",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address2"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address3",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address3"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address4",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address4"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 50, "Country"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("County",
System.Data.OleDb.OleDbType.VarWChar, 50, "County"))

peopleInsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("DOB",
System.Data.OleDb.OleDbType.DBDate, 0, "DOB"))

peopleInsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Email",
System.Data.OleDb.OleDbType.VarWChar, 50, "Email"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 20, "FirstName"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Home_Phone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Home Phone"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 20, "LastName"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("MiddleInnitial",
System.Data.OleDb.OleDbType.VarWChar, 3, "MiddleInnitial"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Mobile_Fone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Mobile Fone"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Post_Code",
System.Data.OleDb.OleDbType.VarWChar, 10, "Post Code"))

peopleInsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Town",
System.Data.OleDb.OleDbType.VarWChar, 50, "Town"))

'

daPeople.InsertCommand = 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.OleDb.OleDbParameter("Address1",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address1"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address2",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address2"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address3",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address3"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address4",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address4"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 50, "Country"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("County",
System.Data.OleDb.OleDbType.VarWChar, 50, "County"))

peopleUpdateCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("DOB",
System.Data.OleDb.OleDbType.DBDate, 0, "DOB"))

peopleUpdateCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Email",
System.Data.OleDb.OleDbType.VarWChar, 50, "Email"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 20, "FirstName"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Home_Phone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Home Phone"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 20, "LastName"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("MiddleInnitial",
System.Data.OleDb.OleDbType.VarWChar, 3, "MiddleInnitial"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Mobile_Fone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Mobile Fone"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Post_Code",
System.Data.OleDb.OleDbType.VarWChar, 10, "Post Code"))

peopleUpdateCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Town",
System.Data.OleDb.OleDbType.VarWChar, 50, "Town"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_ID",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"ID", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address1", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 2",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address2", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 3",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address3", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 4",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address4", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Country ",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Country", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_County" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byt),
"County", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_DOB",
System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email1" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_FirstNa me",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"FirstName", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Home_Ph one",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Home Phone", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_LastNam e",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"LastName", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial1",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Post_Co de",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Post Code", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Town",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Town", System.Data.DataRowVersion.Original, Nothing))

daPeople.UpdateCommand = 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.OleDb.OleDbParameter("Original_ID",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"ID", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address1", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 2",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address2", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 3",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address3", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 4",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Address4", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Country ",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Country", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_County" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"County", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_DOB",
System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email1" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Email", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_FirstNa me",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"FirstName", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Home_Ph one",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Home Phone", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_LastNam e",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"LastName", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial1",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Post_Co de",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Post Code", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Town",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"Town", System.Data.DataRowVersion.Original, Nothing))

'

daPeople.DeleteCommand = peopleDeleteCmd

'Initialise Events

Try

tableEvents.Clear()

dgEvents.DataSource = tableEvents

eventsSelectCmd.CommandType = CommandType.Text

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

eventsSelectCmd.Connection = con

eventsSelectCmd.Parameters.Add("@ID",
dgPeople.Item(dgPeople.CurrentRowIndex, 0))

daEvents.SelectCommand = eventsSelectCmd

daEvents.Fill(tableEvents)

Catch ex As OleDbException

MessageBox.Show(ex.Message)

Catch ex As ArgumentException

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.net> 在郵件
news:bq**********@hercules.btinternet.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

P: n/a
THX for your help

"One Handed Man" <Bo****@Duck.net> 在郵件
news:bq**********@hercules.btinternet.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.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""C:\Documents and Settings\Administrator\My
Documents\" & _

"FamilyPlusFriends.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0" & _

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

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

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

"OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global
Bulk T" & _

"ransactions=1"

daEvents.TableMappings.AddRange(New System.Data.Common.DataTableMapping()
{New System.Data.Common.DataTableMapping("Table", "Events", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("Action", "Action"), New
System.Data.Common.DataColumnMapping("Comments", "Comments"), New
System.Data.Common.DataColumnMapping("Date", "Date"), New
System.Data.Common.DataColumnMapping("EventType", "EventType"), New
System.Data.Common.DataColumnMapping("ID", "ID"), New
System.Data.Common.DataColumnMapping("PersonIndex" , "PersonIndex")})})

daPeople.TableMappings.AddRange(New System.Data.Common.DataTableMapping()
{New System.Data.Common.DataTableMapping("Table", "People", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("Address1", "Address1"), New
System.Data.Common.DataColumnMapping("Address2", "Address2"), New
System.Data.Common.DataColumnMapping("Address3", "Address3"), New
System.Data.Common.DataColumnMapping("Address4", "Address4"), New
System.Data.Common.DataColumnMapping("Country", "Country"), New
System.Data.Common.DataColumnMapping("County", "County"), New
System.Data.Common.DataColumnMapping("DOB", "DOB"), New
System.Data.Common.DataColumnMapping("Email", "Email"), New
System.Data.Common.DataColumnMapping("FirstName", "FirstName"), New
System.Data.Common.DataColumnMapping("Home Phone", "Home Phone"), New
System.Data.Common.DataColumnMapping("LastName", "LastName"), New
System.Data.Common.DataColumnMapping("MiddleInniti al", "MiddleInnitial"),
New System.Data.Common.DataColumnMapping("Mobile Fone", "Mobile Fone"), New System.Data.Common.DataColumnMapping("Post Code", "Post Code"), New
System.Data.Common.DataColumnMapping("Town", "Town"), New
System.Data.Common.DataColumnMapping("ID", "ID")})})

'open connection

con.Open()

'Initialise People

SetPrimaryKeys()

dgPeople.DataSource = tablePeople

peopleSelectCmd.CommandText = "SELECT ID,FirstName,LastName,DOB,[Mobile
Fone],[Home Phone],Email, Address1, Address2,Address3, Address4,Town, [Post Code], County, Country,MiddleInnitial FROM(People)ORDER BY FirstName"

peopleSelectCmd.CommandType = CommandType.Text

peopleSelectCmd.Connection = con

daPeople.SelectCommand = peopleSelectCmd

daPeople.Fill(tablePeople)

'Set up the People insert command

peopleInsertCmd.CommandType = CommandType.Text

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.OleDb.OleDbParameter("Address1",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address1"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address2",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address2"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address3",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address3"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address4",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address4"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 50, "Country"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("County",
System.Data.OleDb.OleDbType.VarWChar, 50, "County"))

peopleInsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("DOB",
System.Data.OleDb.OleDbType.DBDate, 0, "DOB"))

peopleInsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Email", System.Data.OleDb.OleDbType.VarWChar, 50, "Email"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 20, "FirstName"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Home_Phone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Home Phone"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 20, "LastName"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("MiddleInnitial",
System.Data.OleDb.OleDbType.VarWChar, 3, "MiddleInnitial"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Mobile_Fone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Mobile Fone"))

peopleInsertCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Post_Code",
System.Data.OleDb.OleDbType.VarWChar, 10, "Post Code"))

peopleInsertCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Town", System.Data.OleDb.OleDbType.VarWChar, 50, "Town"))

'

daPeople.InsertCommand = 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.OleDb.OleDbParameter("Address1",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address1"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address2",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address2"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address3",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address3"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Address4",
System.Data.OleDb.OleDbType.VarWChar, 50, "Address4"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Country",
System.Data.OleDb.OleDbType.VarWChar, 50, "Country"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("County",
System.Data.OleDb.OleDbType.VarWChar, 50, "County"))

peopleUpdateCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("DOB",
System.Data.OleDb.OleDbType.DBDate, 0, "DOB"))

peopleUpdateCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Email", System.Data.OleDb.OleDbType.VarWChar, 50, "Email"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("FirstName",
System.Data.OleDb.OleDbType.VarWChar, 20, "FirstName"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Home_Phone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Home Phone"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("LastName",
System.Data.OleDb.OleDbType.VarWChar, 20, "LastName"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("MiddleInnitial",
System.Data.OleDb.OleDbType.VarWChar, 3, "MiddleInnitial"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Mobile_Fone",
System.Data.OleDb.OleDbType.VarWChar, 50, "Mobile Fone"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Post_Code",
System.Data.OleDb.OleDbType.VarWChar, 10, "Post Code"))

peopleUpdateCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("Town", System.Data.OleDb.OleDbType.VarWChar, 50, "Town"))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_ID",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address1", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 2",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address2", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 3",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address3", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 4",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address4", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Country ",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Country", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_County" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirectin.Input, False, CType(0, Byte), CType(0, Byte), "County", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_DOB",
System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email1" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_FirstNa me",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "FirstName", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Home_Ph one",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Home Phone", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_LastNam e",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "LastName", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial1",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Post_Co de",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Post Code", System.Data.DataRowVersion.Original, Nothing))

peopleUpdateCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Town",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Town", System.Data.DataRowVersion.Original, Nothing))

daPeople.UpdateCommand = 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.OleDb.OleDbParameter("Original_ID",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ID", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address1", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 2",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address2", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 3",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address3", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Address 4",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address4", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Country ",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Country", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_County" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "County", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_DOB",
System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "DOB",
System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Email1" ,
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_FirstNa me",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "FirstName", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Home_Ph one",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Home Phone", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_LastNam e",
System.Data.OleDb.OleDbType.VarWChar, 20,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "LastName", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_MiddleI nnitial1",
System.Data.OleDb.OleDbType.VarWChar, 3,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MiddleInnitial", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Mobile_ Fone1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Mobile Fone", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Post_Co de",
System.Data.OleDb.OleDbType.VarWChar, 10,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Post Code", System.Data.DataRowVersion.Original, Nothing))

peopleDeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_Town",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Town", System.Data.DataRowVersion.Original, Nothing))

'

daPeople.DeleteCommand = peopleDeleteCmd

'Initialise Events

Try

tableEvents.Clear()

dgEvents.DataSource = tableEvents

eventsSelectCmd.CommandType = CommandType.Text

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

eventsSelectCmd.Connection = con

eventsSelectCmd.Parameters.Add("@ID",
dgPeople.Item(dgPeople.CurrentRowIndex, 0))

daEvents.SelectCommand = eventsSelectCmd

daEvents.Fill(tableEvents)

Catch ex As OleDbException

MessageBox.Show(ex.Message)

Catch ex As ArgumentException

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.net> 在郵件
news:bq**********@hercules.btinternet.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 discussion thread is closed

Replies have been disabled for this discussion.