|
-
Jun 27th, 2003, 10:52 AM
#1
Thread Starter
Sleep mode
Create new table ? [Resolved]
with code and append it to the database file ?
Last edited by Pirate; Jun 28th, 2003 at 10:40 AM.
-
Jun 27th, 2003, 12:19 PM
#2
Registered User
You can perform all these operations through a SQLCommand object by writing the command text for your operation, i.e. "Create Table etc......" then just perform an execute non query on the command object.
LS
-
Jun 27th, 2003, 12:36 PM
#3
Thread Starter
Sleep mode
Can you give me the complete command statement ?
Thanks for your help !
-
Jun 27th, 2003, 07:57 PM
#4
Thread Starter
Sleep mode
-
Jun 28th, 2003, 06:55 AM
#5
Addicted Member
-
Jun 28th, 2003, 07:43 AM
#6
Thread Starter
Sleep mode
MS Access (.mdb) .
-
Jun 28th, 2003, 09:08 AM
#7
Lively Member
This might help. Change the CREATE PROCEDURE to CREATE TABLE and SQL to OLEDB
http://msdn.microsoft.com/library/de...operations.asp
[Visual Basic]
Dim createStr As String = "CREATE PROCEDURE InsertCategory " & _
" @CategoryName nchar(15), " & _
" @Identity int OUT " & _
"AS " & _
"INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " & _
"SET @Identity = @@Identity " & _
"RETURN @@ROWCOUNT"
Dim createCMD As SqlCommand = New SqlCommand(createStr, nwindConn)
createCMD.ExecuteNonQuery()
[C#]
string createStr = "CREATE PROCEDURE InsertCategory " +
" @CategoryName nchar(15), " +
" @Identity int OUT " +
"AS " +
"INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " +
"SET @Identity = @@Identity " +
"RETURN @@ROWCOUNT";
SqlCommand createCMD = new SqlCommand(createStr, nwindConn);
createCMD.ExecuteNonQuery();
-
Jun 28th, 2003, 10:37 AM
#8
Thread Starter
Sleep mode
That's for SQL Server . Apprently there is no way for MS Access by .NET . anyways . I used ADOX and it seems to work fine , though I hate doing things through interoperate. but eh .
Thanks everyone . Edneeis gave me a good solution .
-
Jun 28th, 2003, 10:39 AM
#9
Thread Starter
Sleep mode
Hmm , if anyone got .NET solution for MS Access , plz inform me . I really need that .
Thank you .
-
Jun 28th, 2003, 11:22 AM
#10
Lively Member
-
Jun 28th, 2003, 11:34 AM
#11
Thread Starter
Sleep mode
I'm testing it and error raised saying "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll " on this line
string createStr = "CREATE TABLE Employee(EmpID varchar (50) not null, City varchar (50), FirstName varchar (50)) " ;
What the heck is that ?
Thank you ggprogram .
-
Jun 28th, 2003, 11:38 AM
#12
Thread Starter
Sleep mode
This is one part of your connection string . It's expecting a database in this path with the name "RentalInfo.mdb" , Is this possible ? I mean I will create one . Would it be matter if I change this to :
Application.StartUp + .... ?
Code:
Data Source=C:\Documents and Settings\Glenn\My Documents\My Data Sources\RentalInfo.mdb
-
Jun 28th, 2003, 12:50 PM
#13
Lively Member
Originally posted by Pirate
This is one part of your connection string . It's expecting a database in this path with the name "RentalInfo.mdb" , Is this possible ? I mean I will create one . Would it be matter if I change this to :
Application.StartUp + .... ?
Code:
Data Source=C:\Documents and Settings\Glenn\My Documents\My Data Sources\RentalInfo.mdb
RentalInfo is the mdb file I was creating the table in. You should be able to change it to anything you want.
-
Jun 28th, 2003, 12:55 PM
#14
Lively Member
BTW, the code I gave you will generate an error if you run it a second time. Like I said, it was just quick and dirty. If you create the table in the MDB file and then run the program again,it will try to create a table with CREATE TABLE that already exists, which throws an error.
-
Jun 28th, 2003, 12:56 PM
#15
Thread Starter
Sleep mode
-
Jun 28th, 2003, 12:59 PM
#16
Thread Starter
Sleep mode
Originally posted by ggprogram
BTW, the code I gave you will generate an error if you run it a second time. Like I said, it was just quick and dirty. If you create the table in the MDB file and then run the program again,it will try to create a table with CREATE TABLE that already exists, which throws an error.
No worries , if it runs once , I'll run twice . Got that .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|