Here you can take table name as value from textbox, with that name you can create table at database.
protected void Page_Load(object sender, EventArgs e)
{
}
private string GetConnectionString()
{
//sets the connection string from your web config file. "DBConnection" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
}
public bool DeleteData(string TableName)
{
SqlConnection connection = new SqlConnection(GetConnectionString());
connection.Open();
string sqlStatement = "CREATE TABLE " + TableName + "" + "(studentid INTEGER PRIMARY KEY," + "stuname CHAR(50), stuaddress CHAR
(255), stubalance FLOAT)";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
sqlCmd.ExecuteNonQuery();
connection.Close();
return true;
}
protected void Button1_Click(object sender, EventArgs e)
{
string a = TextBox1.Text;
DeleteData(a);
}
Create database table using c#.net with variable of table name
Create database table using c#.net with variable of table name
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Sreejith ParaliPosted Feb 16, 2016, 2:11 AM
just a code that i was in need thanks.