|
Hi all,
Possibly my first post, if not certainly for a while.
I have a simple C# program which is creating a table in a MySQL db, I want to know how to find out if the table exists already before creating the table. Had a look on the net and here, nothing really answers my question.
Can anyone help?
FYI: Running, VS2005, MySql 5.0.41 and .NET Framework 2
Thanks
AD2
Do not disturb, I'm disturbed enough as it is!
|
|
|
|
|
Try IF NOT EXISTS `Schema`.`Table` to test the table.
|
|
|
|
|
This is the table creation syntax
CREATE TABLE IF NOT EXISTS YourTableName
(create_definition,...)
[table_option] ... Is this what you are looking for ?
|
|
|
|
|
I'm aware of this capability, however there is potential for the table structure to change and if it exists there was problem when the function ran previously and I would want to delete the table.
The program is being used to update a MySQL Db from an Access db
Is IF NOT EXISTS an instruction in its own right?
Do not disturb, I'm disturbed enough as it is!
|
|
|
|
|
Have a look at OdbcConnection.GetSchema. This should help you.
|
|
|
|
|
I want to script a database in sql 2005, i only succeeded in scripting only the objects, but without tables data. How do i achieve my mission
|
|
|
|
|
|
You can also use the AFC Data Unoader - its free.
AFC Data Unloader
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
I installed SQL Server 2005 on my pc, but i didn't get default databases like(northwind, adventureworks...etc).
anybody help me how to get/install these default databases
steps or link will be appriciated.
thanks
Ramana
|
|
|
|
|
|
what is the difference between sql,ms sql and sqlserver 2000
Signature preview salil_k_singh 11:06 15 Jul '07
|
|
|
|
|
SQL is the generic term for the programming language used to query databases, for example select column1 from table1
MS SQL is the gerneric term for Microsft's implementation of SQL or it is sometimes used as the generic name for any of Microsoft's SQL Server versions
SQL Server 2000 is s specific version of Microsoftd database system, SQL Server
Hope this clarifies
Bob
Ashfield Consultants Ltd
|
|
|
|
|
This sounds like a homework problem
|
|
|
|
|
Hi All,
I have some prob in c#.So i want to CREATE a TABLE on Button's "click" event.That's mean when I click on "ok" botton "a new table have to create on my existing DATABASE ".So how i do it in C#..?
ReGardZ
"ChiNthaKa"
CheeN
|
|
|
|
|
The same as you do any other time, issue a CREATE TABLE command - for example
CREATE TABLE Fred(Column1 int NOT NULL, Column2 varchar(50) NULL...etc)
Bob
Ashfield Consultants Ltd
|
|
|
|
|
|
yep, thats another way
Bob
Ashfield Consultants Ltd
|
|
|
|
|
yep
I Love T-SQL
|
|
|
|
|
Hi Chinthaka ,
You can write the following code in the button onclick event . Before that you should import System.Data.SqlClient namespace .
<br />
SqlConnection conn= new SqlConnection("ConnectionString");<br />
conn.Open();<br />
MessageBox.Show("Connection est.."); <br />
SqlCommand comCreate = new SqlCommand("CREATE TABLE EMP_TABLE_CREATE(EmpID INT , EmpName VARCHAR(20))",conn);<br />
int intCreate = comCreate.ExecuteNonQuery();<br />
MessageBox.Show("Table Created.." + intCreate); <br />
SqlCommand conInsert = new SqlCommand("INSERT INTO EMP_TABLE_CREATE VALUES(11,'MyName')",conn ) ;<br />
int intInsert = conInsert.ExecuteNonQuery(); <br />
MessageBox.Show("Row Inserted.." + intInsert); <br />
MessageBox.Show("Displaying Row : "); <br />
SqlCommand conSelect = new SqlCommand("SELECT * FROM EMP_TABLE_CREATE",conn) ;<br />
SqlDataReader dr= conSelect.ExecuteReader(); <br />
dr.Read();<br />
while(dr.HasRows)<br />
{<br />
MessageBox.Show(dr.GetInt32(0).ToString() +":"+dr.GetString(1)) ; <br />
dr.NextResult(); <br />
}<br />
conn.Close(); <br />
Hope this is what you wanted . Let me know if you have any further queries .
Thanks
Priya Rohan
|
|
|
|
|
Hi, in SQL Express when we design the table, which option/data type that could set the field as auto number like in Microsoft access? Thank in advance
|
|
|
|
|
Ok, now i found it. It is locate in Identify Specification
|
|
|
|
|
I'm trying to find out how many records are in a table using this code but I keep getting -1 for n.
Dim command As String, data As ADODB.Recordset, n As Integer<br />
<br />
rsGuest.Open("Guest", ADOConnection,ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)<br />
command = "SELECT [Guest ID] from Guest"<br />
<br />
data = ADOConnection.Execute(command)<br />
n = data.RecordCount
I read on another webisite that I need to add this line:
data.CursorLocation = ADODB.CursorLocationEnum.adUseClient
but when I do I get this error:
Operation is not allowed when the object is open.
So what should I do. Thank you for your help.
Mike
|
|
|
|
|
forgot to add I'm doing this with vb.net 2005 with microsoft access 2007.
|
|
|
|
|
If you are using vb.net , I would recomment using the System.Data.Oledb classes rather than com interop with ADODB. It would be both easier and more performant.
To get the number of records currently in a table Use "Select Count(*) as nRecs from Mytable" for your query.
For your ADODB approach to work, you have to navigate to the end of the recordset before the count is accurate (use Recordset.MoveLast). Obviously, this is slow...
To changed to a client side cursor, set the cursortype variable BEFORE opening the connection.
Hope thies suggestions help.
|
|
|
|
|
Hi,
you could try a SELECT COUNT(*) FROM Guest and use ExecuteScalar, then
cast to integer.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|