Group:  Microsoft Excel ยป microsoft.public.excel.querydao
Thread: Connection Object basics

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Connection Object basics
itsyash[ at ]gmail.com 02.09.2006 12:10:47
I need to enter data from Excel VBA into SQL.

I am trying to use the query mentioned below: My challenge is that I am
in a wonderland when it comes to SQL and connection objects. I dont
know what I should have in "Data Source=Server\SQLServer;"
and "Initial Catalog=MyDatabase"

I think 'data source' should be as it is and 'Initial Catalog' should
be the database name. I dont know where the authentication should be
done. I dont have a password for SQL, username is sa.

Please guide me...

Sub SQLServerInsert()


Dim objCommand As ADODB.Command


''' Create the Command object.
Set objCommand = New ADODB.Command
objCommand.ActiveConnection = "Provider=SQLOLEDB;" & _
"Data Source=Server\SQLServer;" & _
"Initial Catalog=MyDatabase"


''' Load the SQL string into the Command object.
objCommand.CommandText = "INSERT INTO MyTable" & _
"(Field1, Field2, Field3, Field4) " & _
"VALUES(Value1, Value2, Value3, Value4)"


''' Execute the SQL statement.
objCommand.Execute


Set objCommand = Nothing


End Sub


Thanks in advance,
Yash

Re: Connection Object basics
"Andy Wiggins" <contact me via my website at www.BygSoftware.com> 02.09.2006 22:37:12
As a first step, record a query using Ms Query. The resulting code will give
you the connection data you need.

--
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy
-

<itsyash[ at ]gmail.com> wrote in message
news:1157199047.002859.90530[ at ]p79g2000cwp.googlegroups.com...
[Quoted Text]
>I need to enter data from Excel VBA into SQL.
>
> I am trying to use the query mentioned below: My challenge is that I am
> in a wonderland when it comes to SQL and connection objects. I dont
> know what I should have in "Data Source=Server\SQLServer;"
> and "Initial Catalog=MyDatabase"
>
> I think 'data source' should be as it is and 'Initial Catalog' should
> be the database name. I dont know where the authentication should be
> done. I dont have a password for SQL, username is sa.
>
> Please guide me...
>
> Sub SQLServerInsert()
>
>
> Dim objCommand As ADODB.Command
>
>
> ''' Create the Command object.
> Set objCommand = New ADODB.Command
> objCommand.ActiveConnection = "Provider=SQLOLEDB;" & _
> "Data Source=Server\SQLServer;" & _
> "Initial Catalog=MyDatabase"
>
>
> ''' Load the SQL string into the Command object.
> objCommand.CommandText = "INSERT INTO MyTable" & _
> "(Field1, Field2, Field3, Field4) " & _
> "VALUES(Value1, Value2, Value3, Value4)"
>
>
> ''' Execute the SQL statement.
> objCommand.Execute
>
>
> Set objCommand = Nothing
>
>
> End Sub
>
>
> Thanks in advance,
> Yash
>


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net