Nothing happening to my database, when i run I get no errors, build is succeded, only label text s displayed but not the creation on Tabel. please help me guys.
namespace Waafe_version_1._0
{
public partial class adminaddsemester : System.Web.UI.Page
{
private List<String> year = new List<String>();
private List<String> semester = new List<String>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList2.DataSource = GetYears();
DropDownList2.DataBind();
DropDownList1.DataSource = Getsemester();
DropDownList1.DataBind();
}
}
public List<String> GetYears()
{
string startingYear = "2000";
DateTime startYear = Convert.ToDateTime("01/01/" + startingYear);
for (int i = 0; i < 20; i++)
{
int year1 = startYear.AddYears(i).Year;
int year2 = startYear.AddYears(i + 4).Year;
String yearfinal = year1.ToString() + year2.ToString();
year.Add(yearfinal);
}
return year;
}
public List<String> Getsemester()
{
for (int i = 1; i < 9; i++)
{
string year1 = "semester"+i;
semester.Add(year1);
}
return semester;
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=SARATH-31201114\\SQLEXPRESS;Initial Catalog='" +
DropDownList2.SelectedValue + "' ;User ID=sa;Password=T0Ge+Da+a");
con.Open();
if(DropDownList1.SelectedValue=="semester1")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER1]( [Registerationnumber] [numeric](11, 0) NOT NULL,
[Studentname] [char](50) NOT NULL, [HS2111Technicalenglish1] [char](1) NOT NULL, [MA2111Mathematics1] [char](1) NOT NULL,
[PH2111Engineeringphysics1] [char](1) NOT NULL, [CY2111Engineeringchemistry1] [char](1) NOT NULL,
[GE2111Engineeringgraphics] [char](1) NOT NULL, [GE2112Fundamentalsofcomputingandprogramming] [char](1) NOT NULL,
[GE2115Computerpracticelaboratory1] [char](1) NOT NULL, [GE2116Engineeringpracticelaboratory1] [char](1) NOT NULL", con);
}
else if (DropDownList1.SelectedValue == "semester2")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER2]( [Registerationnumber] [numeric](11, 0) NOT NULL,
[Studentname] [char](50) NOT NULL, [HS2161Technicalenglish2] [char](1) NOT NULL, [MA2161Mathematics2] [char](1) NOT NULL,
[PH2161Engineeringphysics2] [char](1) NOT NULL, [CY2161Engineeringchemistry2] [char](1) NOT NULL,
[EC2151Electriccircuitsandelectrondevices] [char](1) NOT NULL, [GE2152Basiccivilandmechanicalengineering] [char](1) NOT NULL, [GE2155Computerpracticelaboratory2] [char](1) NOT NULL, [GS2165Engineeringpracticelaboratory1] [char](1) NOT NULL", con);
}
else if (DropDownList1.SelectedValue == "semester3")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER3]( [Registerationnumber] [numeric](11, 0) NOT NULL,
[Studentname] [char](50) NOT NULL, [MA2211Transformsandpartialdifferentialeqations] [char](1) NOT NULL,
[CS2203Objectorientedprogramming] [char](1) NOT NULL, [CS2202Digitalprinciplesandsystemdesign] [char](1) NOT NULL,
[IT2201Datastructuresandalgorithm] [char](1) NOT NULL, [IT2202Principlesofcommunication] [char](1) NOT NULL,
[GE2021Environmentalscienceandengineering] [char](1) NOT NULL, [CS2207Digitallab] [char](1) NOT NULL,
[IT2205Datastructuresandalgorithmlab] [char](1) NOT NULL, [CS2209Objectorientedprogramminglab] [char](1) NOT NULL", con);
}
else if (DropDownList1.SelectedValue == "semester4")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER4]( [Registerationnumber] [numeric](11, 0) NULL,
[Studentname] [nchar](20) NULL, [MA2262Probilityandqueuingtheory] [char](1) NOT NULL,
[CS2255Databasemanagementandsystems] [char](1) NOT NULL, [CS2252Microprocessorandmicrocontrollers] [char](1) NOT NULL,
[CS2253Computerorganisationandarchitecture] [char](1) NOT NULL, [CS2254Operatingsystems] [char](1) NOT NULL,
[IT2251Softwareengineeringandqualityassurance] [char](1) NOT NULL, [CS2258Databasemanagementandsystemslab] [char](1) NOT
NULL, [CS2257Operatingsystemslab] [char](1) NOT NULL, [CS2259Microprocessorlab] [char](1) NOT NULL", con);
}
else if (DropDownList1.SelectedValue == "semester5")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER5]( [Registerationnumber] [numeric](11, 0) NOT NULL,
[Studentname] [char](50) NOT NULL, [IT2301Javaprogramming] [char](1) NOT NULL,
[MG2452Engineeringeconomicsandfinancialaccounting] [char](1) NOT NULL, [CS2304Systemsoftware] [char](1) NOT NULL,
[CS2302Computernetworks] [char](1) NOT NULL, [CS2403Digigtalsignalprocessing] [char](1) NOT NULL,
[IT2302Informationtheroyandcoding] [char](1) NOT NULL, [CS2308Systemsoftwarelab] [char](1) NOT NULL,
[IT2305Javaprogramminglab] [char](1) NOT NULL, [GE2321Communicationskillslab] [char](1) NOT NULL", con);
}
else if (DropDownList1.SelectedValue == "semester6")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER6]( [Registerationnumber] [numeric](11, 0) NOT NULL,
[Studentname] [char](50) NOT NULL, [IT2351Networkprogrammingandmanagement] [char](1) NOT NULL,
[CS2353Objectorientedanalysisanddesign] [char](1) NOT NULL, [IT2352Cryptographyandnetworksecurity] [char](1) NOT NULL,
[IT2353Webtechnology] [char](1) NOT NULL, [IT2354Embeddedsystems] [char](1) NOT NULL, [Elective] [char](1) NOT NULL,
[IT2357Webtechnologylab] [char](1) NOT NULL, [CS2357Objectorientedanalysisanddesignlab] [char](1) NOT NULL,
[CS2307Networklab] [char](1) NOT NULL", con);
}
else if (DropDownList1.SelectedValue == "semester7")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER7]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2401Serviceorientedarchitecture] [char](1) NOT NULL, [IT2402Mobilecommunication] [char]
(1) NOT NULL, [CS2401Computergraphics] [char](1) NOT NULL, [IT2403Softwareprojectmanagement] [char](1) NOT NULL,
[Elective2] [char](1) NOT NULL, [Elective3] [char](1) NOT NULL, [IT2406Serviceorientedarchitecturelab] [char](1) NOT NULL,
[CS2405Computergraphicslab] [char](1) NOT NULL ", con);
}
else if (DropDownList1.SelectedValue == "semester8")
{
SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER8]( [Registerationnumber] [numeric](11, 0) NOT NULL,
[Studentname] [char](50) NOT NULL, [Elective4] [char](1) NOT NULL, [Elective5] [char](1) NOT NULL, [IT2451Projectwork] [char]
(1) NOT NULL", con);
}
Label2.Text = "you successfully created a database table '" + DropDownList1.SelectedValue + "' in batch '" +
DropDownList2.SelectedValue + "' ";
}
}
Its possible that the dropdown2 value may indeed be the catalog, like 2000 could be for students in that year and so on. Depends alot on the databases that live on the db server. Initial catalog is database name for all intents and purposes.
I have to ask you why are you creating tables on the fly? Why not use tried and true methods instead? This type of scenario may not be the best security wise. Take a look at this thread before you hop down the bunny trail too far :)
its like creating the databases with year names from the list of dropdown listbox,,,,, and to create a table with the pakka columns and that table name shd also be from drop down list ......
sarathbabu12
Member
14 Points
12 Posts
error in creating a table dynamically
Feb 21, 2012 04:10 PM|LINK
Nothing happening to my database, when i run I get no errors, build is succeded, only label text s displayed but not the creation on Tabel. please help me guys.
namespace Waafe_version_1._0 { public partial class adminaddsemester : System.Web.UI.Page { private List<String> year = new List<String>(); private List<String> semester = new List<String>(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList2.DataSource = GetYears(); DropDownList2.DataBind(); DropDownList1.DataSource = Getsemester(); DropDownList1.DataBind(); } } public List<String> GetYears() { string startingYear = "2000"; DateTime startYear = Convert.ToDateTime("01/01/" + startingYear); for (int i = 0; i < 20; i++) { int year1 = startYear.AddYears(i).Year; int year2 = startYear.AddYears(i + 4).Year; String yearfinal = year1.ToString() + year2.ToString(); year.Add(yearfinal); } return year; } public List<String> Getsemester() { for (int i = 1; i < 9; i++) { string year1 = "semester"+i; semester.Add(year1); } return semester; } protected void LinkButton1_Click(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=SARATH-31201114\\SQLEXPRESS;Initial Catalog='" + DropDownList2.SelectedValue + "' ;User ID=sa;Password=T0Ge+Da+a"); con.Open(); if(DropDownList1.SelectedValue=="semester1") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER1]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [HS2111Technicalenglish1] [char](1) NOT NULL, [MA2111Mathematics1] [char](1) NOT NULL, [PH2111Engineeringphysics1] [char](1) NOT NULL, [CY2111Engineeringchemistry1] [char](1) NOT NULL, [GE2111Engineeringgraphics] [char](1) NOT NULL, [GE2112Fundamentalsofcomputingandprogramming] [char](1) NOT NULL, [GE2115Computerpracticelaboratory1] [char](1) NOT NULL, [GE2116Engineeringpracticelaboratory1] [char](1) NOT NULL", con); } else if (DropDownList1.SelectedValue == "semester2") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER2]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [HS2161Technicalenglish2] [char](1) NOT NULL, [MA2161Mathematics2] [char](1) NOT NULL, [PH2161Engineeringphysics2] [char](1) NOT NULL, [CY2161Engineeringchemistry2] [char](1) NOT NULL, [EC2151Electriccircuitsandelectrondevices] [char](1) NOT NULL, [GE2152Basiccivilandmechanicalengineering] [char](1) NOT NULL, [GE2155Computerpracticelaboratory2] [char](1) NOT NULL, [GS2165Engineeringpracticelaboratory1] [char](1) NOT NULL", con); } else if (DropDownList1.SelectedValue == "semester3") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER3]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [MA2211Transformsandpartialdifferentialeqations] [char](1) NOT NULL, [CS2203Objectorientedprogramming] [char](1) NOT NULL, [CS2202Digitalprinciplesandsystemdesign] [char](1) NOT NULL, [IT2201Datastructuresandalgorithm] [char](1) NOT NULL, [IT2202Principlesofcommunication] [char](1) NOT NULL, [GE2021Environmentalscienceandengineering] [char](1) NOT NULL, [CS2207Digitallab] [char](1) NOT NULL, [IT2205Datastructuresandalgorithmlab] [char](1) NOT NULL, [CS2209Objectorientedprogramminglab] [char](1) NOT NULL", con); } else if (DropDownList1.SelectedValue == "semester4") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER4]( [Registerationnumber] [numeric](11, 0) NULL, [Studentname] [nchar](20) NULL, [MA2262Probilityandqueuingtheory] [char](1) NOT NULL, [CS2255Databasemanagementandsystems] [char](1) NOT NULL, [CS2252Microprocessorandmicrocontrollers] [char](1) NOT NULL, [CS2253Computerorganisationandarchitecture] [char](1) NOT NULL, [CS2254Operatingsystems] [char](1) NOT NULL, [IT2251Softwareengineeringandqualityassurance] [char](1) NOT NULL, [CS2258Databasemanagementandsystemslab] [char](1) NOT NULL, [CS2257Operatingsystemslab] [char](1) NOT NULL, [CS2259Microprocessorlab] [char](1) NOT NULL", con); } else if (DropDownList1.SelectedValue == "semester5") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER5]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2301Javaprogramming] [char](1) NOT NULL, [MG2452Engineeringeconomicsandfinancialaccounting] [char](1) NOT NULL, [CS2304Systemsoftware] [char](1) NOT NULL, [CS2302Computernetworks] [char](1) NOT NULL, [CS2403Digigtalsignalprocessing] [char](1) NOT NULL, [IT2302Informationtheroyandcoding] [char](1) NOT NULL, [CS2308Systemsoftwarelab] [char](1) NOT NULL, [IT2305Javaprogramminglab] [char](1) NOT NULL, [GE2321Communicationskillslab] [char](1) NOT NULL", con); } else if (DropDownList1.SelectedValue == "semester6") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER6]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2351Networkprogrammingandmanagement] [char](1) NOT NULL, [CS2353Objectorientedanalysisanddesign] [char](1) NOT NULL, [IT2352Cryptographyandnetworksecurity] [char](1) NOT NULL, [IT2353Webtechnology] [char](1) NOT NULL, [IT2354Embeddedsystems] [char](1) NOT NULL, [Elective] [char](1) NOT NULL, [IT2357Webtechnologylab] [char](1) NOT NULL, [CS2357Objectorientedanalysisanddesignlab] [char](1) NOT NULL, [CS2307Networklab] [char](1) NOT NULL", con); } else if (DropDownList1.SelectedValue == "semester7") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER7]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2401Serviceorientedarchitecture] [char](1) NOT NULL, [IT2402Mobilecommunication] [char] (1) NOT NULL, [CS2401Computergraphics] [char](1) NOT NULL, [IT2403Softwareprojectmanagement] [char](1) NOT NULL, [Elective2] [char](1) NOT NULL, [Elective3] [char](1) NOT NULL, [IT2406Serviceorientedarchitecturelab] [char](1) NOT NULL, [CS2405Computergraphicslab] [char](1) NOT NULL ", con); } else if (DropDownList1.SelectedValue == "semester8") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER8]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [Elective4] [char](1) NOT NULL, [Elective5] [char](1) NOT NULL, [IT2451Projectwork] [char] (1) NOT NULL", con); } Label2.Text = "you successfully created a database table '" + DropDownList1.SelectedValue + "' in batch '" + DropDownList2.SelectedValue + "' "; } }bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: error in creating a table dynamically
Feb 21, 2012 04:57 PM|LINK
You aren't instructing the sql to execute the command. Use this corrected code:
namespace Waafe_version_1._0 { public partial class adminaddsemester : System.Web.UI.Page { private List<String> year = new List<String>(); private List<String> semester = new List<String>(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList2.DataSource = GetYears(); DropDownList2.DataBind(); DropDownList1.DataSource = Getsemester(); DropDownList1.DataBind(); } } public List<String> GetYears() { string startingYear = "2000"; DateTime startYear = Convert.ToDateTime("01/01/" + startingYear); for (int i = 0; i < 20; i++) { int year1 = startYear.AddYears(i).Year; int year2 = startYear.AddYears(i + 4).Year; String yearfinal = year1.ToString() + year2.ToString(); year.Add(yearfinal); } return year; } public List<String> Getsemester() { for (int i = 1; i < 9; i++) { string year1 = "semester" + i; semester.Add(year1); } return semester; } protected void LinkButton1_Click(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=SARATH-31201114\\SQLEXPRESS;Initial Catalog='" + DropDownList2.SelectedValue + "' ;User ID=sa;Password=T0Ge+Da+a"); con.Open(); if (DropDownList1.SelectedValue == "semester1") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER1]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [HS2111Technicalenglish1] [char](1) NOT NULL, [MA2111Mathematics1] [char](1) NOT NULL, [PH2111Engineeringphysics1] [char](1) NOT NULL, [CY2111Engineeringchemistry1] [char](1) NOT NULL, [GE2111Engineeringgraphics] [char](1) NOT NULL, [GE2112Fundamentalsofcomputingandprogramming] [char](1) NOT NULL, [GE2115Computerpracticelaboratory1] [char](1) NOT NULL, [GE2116Engineeringpracticelaboratory1] [char](1) NOT NULL", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester2") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER2]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [HS2161Technicalenglish2] [char](1) NOT NULL, [MA2161Mathematics2] [char](1) NOT NULL, [PH2161Engineeringphysics2] [char](1) NOT NULL, [CY2161Engineeringchemistry2] [char](1) NOT NULL, [EC2151Electriccircuitsandelectrondevices] [char](1) NOT NULL, [GE2152Basiccivilandmechanicalengineering] [char](1) NOT NULL, [GE2155Computerpracticelaboratory2] [char](1) NOT NULL, [GS2165Engineeringpracticelaboratory1] [char](1) NOT NULL", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester3") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER3]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [MA2211Transformsandpartialdifferentialeqations] [char](1) NOT NULL, [CS2203Objectorientedprogramming] [char](1) NOT NULL, [CS2202Digitalprinciplesandsystemdesign] [char](1) NOT NULL, [IT2201Datastructuresandalgorithm] [char](1) NOT NULL, [IT2202Principlesofcommunication] [char](1) NOT NULL, [GE2021Environmentalscienceandengineering] [char](1) NOT NULL, [CS2207Digitallab] [char](1) NOT NULL, [IT2205Datastructuresandalgorithmlab] [char](1) NOT NULL, [CS2209Objectorientedprogramminglab] [char](1) NOT NULL", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester4") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER4]( [Registerationnumber] [numeric](11, 0) NULL, [Studentname] [nchar](20) NULL, [MA2262Probilityandqueuingtheory] [char](1) NOT NULL, [CS2255Databasemanagementandsystems] [char](1) NOT NULL, [CS2252Microprocessorandmicrocontrollers] [char](1) NOT NULL, [CS2253Computerorganisationandarchitecture] [char](1) NOT NULL, [CS2254Operatingsystems] [char](1) NOT NULL, [IT2251Softwareengineeringandqualityassurance] [char](1) NOT NULL, [CS2258Databasemanagementandsystemslab] [char](1) NOT NULL, [CS2257Operatingsystemslab] [char](1) NOT NULL, [CS2259Microprocessorlab] [char](1) NOT NULL", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester5") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER5]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2301Javaprogramming] [char](1) NOT NULL, [MG2452Engineeringeconomicsandfinancialaccounting] [char](1) NOT NULL, [CS2304Systemsoftware] [char](1) NOT NULL, [CS2302Computernetworks] [char](1) NOT NULL, [CS2403Digigtalsignalprocessing] [char](1) NOT NULL, [IT2302Informationtheroyandcoding] [char](1) NOT NULL, [CS2308Systemsoftwarelab] [char](1) NOT NULL, [IT2305Javaprogramminglab] [char](1) NOT NULL, [GE2321Communicationskillslab] [char](1) NOT NULL", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester6") { SqlCommand com = new SqlCommand("CREATE TABLE [dbo].[SEMESTER6]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2351Networkprogrammingandmanagement] [char](1) NOT NULL, [CS2353Objectorientedanalysisanddesign] [char](1) NOT NULL, [IT2352Cryptographyandnetworksecurity] [char](1) NOT NULL, [IT2353Webtechnology] [char](1) NOT NULL, [IT2354Embeddedsystems] [char](1) NOT NULL, [Elective] [char](1) NOT NULL, [IT2357Webtechnologylab] [char](1) NOT NULL, [CS2357Objectorientedanalysisanddesignlab] [char](1) NOT NULL, [CS2307Networklab] [char](1) NOT NULL", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester7") { SqlCommand com = new SqlCommand("CREATE TABLE [dbo].[SEMESTER7]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [IT2401Serviceorientedarchitecture] [char](1) NOT NULL, [IT2402Mobilecommunication] [char] (1) NOT NULL, [CS2401Computergraphics] [char](1) NOT NULL, [IT2403Softwareprojectmanagement] [char](1) NOT NULL, [Elective2] [char](1) NOT NULL, [Elective3] [char](1) NOT NULL, [IT2406Serviceorientedarchitecturelab] [char](1) NOT NULL, [CS2405Computergraphicslab] [char](1) NOT NULL ", con); com.ExecuteNonQuery(); } else if (DropDownList1.SelectedValue == "semester8") { SqlCommand com = new SqlCommand(" CREATE TABLE [dbo].[SEMESTER8]( [Registerationnumber] [numeric](11, 0) NOT NULL, [Studentname] [char](50) NOT NULL, [Elective4] [char](1) NOT NULL, [Elective5] [char](1) NOT NULL, [IT2451Projectwork] [char] (1) NOT NULL", con); com.ExecuteNonQuery(); } con.Close(); Label2.Text = "you successfully created a database table '" + DropDownList1.SelectedValue + "' in batch '" + DropDownList2.SelectedValue + "' "; } } }vckreddyece
Member
215 Points
52 Posts
Re: error in creating a table dynamically
Feb 21, 2012 04:57 PM|LINK
1) In the below line:
SqlConnection con = new SqlConnection("Data Source=SARATH-31201114\\SQLEXPRESS;Initial Catalog='" + DropDownList2.SelectedValue + "' ;User ID=sa;Password=T0Ge+Da+a");
Make sure that you have passed correct value to Initial Catalog parameter. From your code it looks like DropDownList2 is giving the year.
2) Then follow the section "Practical Learning: Creating a Table" from below link. Follow ADO.Net coding steps.
http://www.functionx.com/vbasic/adonet/Lesson04.htm
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: error in creating a table dynamically
Feb 21, 2012 05:02 PM|LINK
Its possible that the dropdown2 value may indeed be the catalog, like 2000 could be for students in that year and so on. Depends alot on the databases that live on the db server. Initial catalog is database name for all intents and purposes.
sarathbabu12
Member
14 Points
12 Posts
Re: error in creating a table dynamically
Feb 21, 2012 05:17 PM|LINK
{"Incorrect syntax near 'NULL'."}
this is the erro i get when i use com.executenonquery
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: error in creating a table dynamically
Feb 21, 2012 05:21 PM|LINK
I have to ask you why are you creating tables on the fly? Why not use tried and true methods instead? This type of scenario may not be the best security wise. Take a look at this thread before you hop down the bunny trail too far :)
http://stackoverflow.com/questions/5999756/why-creating-tables-in-run-time-code-behind-is-bad
vckreddyece
Member
215 Points
52 Posts
Re: error in creating a table dynamically
Feb 21, 2012 05:22 PM|LINK
sarathbabu12
Member
14 Points
12 Posts
Re: error in creating a table dynamically
Feb 21, 2012 05:25 PM|LINK
its like creating the databases with year names from the list of dropdown listbox,,,,, and to create a table with the pakka columns and that table name shd also be from drop down list ......
sarathbabu12
Member
14 Points
12 Posts
Re: error in creating a table dynamically
Feb 21, 2012 05:28 PM|LINK
for example dropdownist 1 contains
200920013
20102014
etcccc
all the above are database names,, each can hold 8 semesterss
dropdownlist 2
semester1
semester2
semester3
semester4
so to create a 3rd semester in 20092013 batchii have to move my intial catalogue value to the exsisting databse......then i have to cretae a table
i think now i am clearrr,
vckreddyece
Member
215 Points
52 Posts
Re: error in creating a table dynamically
Feb 21, 2012 05:44 PM|LINK