Can I get the data using sql command???

  • Thread starter Thread starter Gene
  • Start date Start date
G

Gene

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?
 
Use the ExecuteNonQuery method of the command object. This will return the
rows affected.

Regards - OHM
 
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!
 
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("MiddleInnitial", "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], " & _

"(e-mail address removed)
 
THX for your help

One Handed Man said:
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("MiddleInnitial", "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], " & _

"(e-mail address removed)
 
Back
Top