what namespaces used to remove the following errors?
my question is that if the user click on button(which is placed in default.aspx,for example) then the database table is created in database(database is placed in sql express 2005)how can do ?.
I try this task by another method but the following errors are occurred:
1.'system.Web.UI.Page.Server' is a 'property' but is used like a 'type'.
2.The type or namespace name 'Database' could not be found(are you missing a using directive or an assembly reference?)
3.The name 'DataType' does not exist in the current context.
4.'System.Web.UI.WebControls.Table' does not contain a definition for 'columns' and no extension method 'columns' accepting a first argument of type 'System.Web.UI.WebControls.Table' could be found(are you missing a using directive or an assembly reference.
5.'System.Data.Index' is inaccessible due to its protection level.
6.'System.Data.Index' does not contain a constructor that takes '2' arguments.
7.'System.Data.Index' does not contain a definition for 'IndexKeyType' and no extension method 'IndexKeyType' accepting a first argument of type 'System.Data.Index' could be found(are you missing a using directive or an assembly reference?)
8.The name 'IndexKeyType' does not exist in the current context.
9.'System.Data.Index' does not contain a definition for'IndexedColumns' and no extension method 'IndexedColumns' accepting a first argument of type 'System.Data.Index' could be found(are you missing a using directive or assembly reference?)
10.The type or namespace name 'Indexedcolumn' could not be found(are you missing a using directive or an assembly reference?)
11.'System.Web开发者_Python百科.UI.WebControls.Table' does not contain a definition for 'Indexes' and no extension method 'Indexes' accepting a first argument of type 'System.Web.UI.Webcontrols.Table' could be found(are you missing a using directive or an assembly reference?)
13.'System.Web.UI.WebControls.Table' does not Contain a definition for 'Create' and no extension method 'Create' accepting a first argument of type 'Systen.Web.UI.WebControls.Table' could be found(are you missing a using directive or an assembly reference?)
The code written in c# behind the button is that:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
//using System.Data.OleDb;
using System.Diagnostics;
using System.ComponentModel;
using System.Text;
using System.Data.SqlClient;
//using System.Data.Odbc;
using Microsoft.SqlServer.Management.Common;
//using ADOX;
//using ADODB;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// Establish the database server
string connectionString = ConfigurationManager.ConnectionStrings["gameConnectionString"].ConnectionString;
SqlConnection connection =
new SqlConnection(connectionString);
Server server =
new Server(new ServerConnection(connection));
// Create table in my personal database
Database db = server.Databases["game"];
// Create new table, called TestTable
Table newTable = new Table(db, "TestTable");
// Add "ID" Column, which will be PK
Column idColumn = new Column(newTable, "ID");
idColumn.DataType = DataType.Int;
idColumn.Nullable = false;
idColumn.Identity = true;
idColumn.IdentitySeed = 1;
idColumn.IdentityIncrement = 1;
// Add "Title" Column
Column titleColumn = new Column(newTable, "Title");
titleColumn.DataType = DataType.VarChar(50);
titleColumn.Nullable = false;
// Add Columns to Table Object
newTable.Columns.Add(idColumn);
newTable.Columns.Add(titleColumn);
// Create a PK Index for the table
Index index = new Index(newTable, "PK_TestTable");
index.IndexKeyType = IndexKeyType.DriPrimaryKey;
// The PK index will consist of 1 column, "ID"
index.IndexedColumns.Add(new IndexedColumn(index, "ID"));
// Add the new index to the table.
newTable.Indexes.Add(index);
// Physically create the table in the database
newTable.Create();
}
}
sir please solve these errors and also give the solution in detail through which i can easily understand.I am very confused in this task please help me.Thank sir
Suggest abandoning your current approach. The problems go beyond namespacing. Suggest taking these steps:
- create a brand new test project for the following
- determine the SQL statements for
- creating a table with all columns
- creating the index
- execute the SQL statements above using ADO.NET. Suggest a
SqlConnection
andSqlCommand
.
Something like this:
using (var conn = new SqlConnection(connString))
{
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = createTableStatement; //CREATE TABLE Foo (ID int);
conn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = createIndexStatement;
cmd.ExecuteNonQuery();
}
}
This will get you started on accomplishing your task. Be sure that any user-entered data aren't simply placed into your strings to create your objects. If so, change the approach to use parameters with your SqlCommand.
Here's an article on Beginner's Guide to Accessing SQL Server Through C#
精彩评论