Hello,
I am doing a project in Visual C#.
1. I want to know how to create an exe file for a Visual C# project.
2. I am using Sql Server 2005 to store my database.I tried to add a new table into the database via code, the project is compiling properly without an error, but then the table is not created.
Pls help me with a solution to the above said problems....
I need them urgently..
Sorry for troubling you!!
Regards,
Sweety

Help needed !!!
Abongs
Actually, the command retrieves the list of user-defined tables from the *current* database. I suspect that you executed the command while connected to the master databse.
As for the DataSource= keyword, you can define a datasource on an individual machine and reference it by name. The definition of the datasource contains the same basic information as a connection string. However, there is no default data source available. Each machine would need to have the one you want to use defined. Trust me when I say that defining the connection string in code or, better yet, in the app.config file, is the way to go.
Rraj
1 . The command which you gave retrieves the list of tables present in the system database, but i need to retrieve the tables present in a user -defined database, can you tell me the command where i can say the name of the database from which the table names need to be retrieved.
2.I asked for the default data source ,because I found a SqlconnectionString where the "DataSource = ." .May I know what does it mean, is it like localhost or any other thing.
Thanks a lot in advance!!!
- Sweety
sjsn
Thanks a lot..it works perfectly.....
1. I just want to know is there any way to display all the tables present in a database...because as far as my project is concerned...the user should be given a list of tables,which can be either edited or deleted from the database.
2. Is there any default Datasource name which can be specified in the connection string , because i am tring to load the same project in 10 systems....so.....that..whenever I load this project in the system , I can make use of that Default DataSource name rather than.....creating one database with the name specified...
Waiting for the reply!!
Regards,
Sweety
aybe
The problem is that creating a SqlDataAdapter is not the same thing as executing the statements used in it. Also, the data adapter shouldn't be used to perform DDL statements, only DML. Try changing it to the following:
string connectionString = "Data Source=Myserver; Initial Catalog=Example; Integrated security=True;";
SqlConnection sqlCN = new SqlConnection(connectionString);
string selectCommandText = "create table login_new (number int)";
try {
SqlCommand sqlCmd = new SqlCommand(selectCommandText, sqlCN);sqlCN.Open();
sqlCmd.ExecuteNonQuery();
sqlCmd.CommandText = "INSERT INTO login_new values(1)";
sqlCmd.ExecuteNonQuery();
selectCommandText = "SELECT * FROM login_new";
sqlDA = new SqlDataAdapter(selectCommandText, sqlCN);
DataSet DS = new DataSet();
sqlDA.Fill(DS);
dataGridView1.DataSource = DS.Tables[0].DefaultView;
}
Naturally, you'll only be able to run this the first time, as the table will be created. The second time it gets executed, the CREATE TABLE SQL statement will throw an exception.
Hope that helps.
reline_sprint
Thanks a lot for providing me the solution for the .exe file creation and regarding the second question , I have provided my code to access the database.
string connectionString = "Data Source=Myserver; Initial Catalog=Example; Integrated security=True;";
SqlConnection
sqlCN = new SqlConnection(connectionString); string selectCommandText = "create table login_new (number int)"; SqlDataAdapter sqlDA = new SqlDataAdapter(selectCommandText, sqlCN);selectCommandText =
"insert into login_new values(1)";sqlDA =
new SqlDataAdapter(selectCommandText, sqlCN); selectCommandText = "SELECT * from login_new"; sqlDA = new SqlDataAdapter(selectCommandText, sqlCN); try {sqlCN.Open();
DataSet
DS = new DataSet();sqlDA.Fill(DS);
dataGridView1.DataSource = DS.Tables[0].DefaultView;
}
I am not able to figure out whats wrong with the code in creating a new table to the database.
I am planning to load this project in more in 10 computers, Is there any default datasource which can be created and accessed or do i need to create the DataSource with the name Myserver to run this project.
Waiting for your replies!!!
bye
Sweety
glavian
Kiranvukkadala
1. The following command retrieves a list of tables in the current database:
SELECT name
FROM sysobjects WITH (NOLOCK)
WHERE xtype = 'U'
2. There is no default datasource name in the way I think you envision. There is no requirement that that database be local to each machine, so you could create the database once and have everyone point to it using (potentially) the same connection string. But I think it's difficult to provide the best answer without a lot more information about what you're trying to accomplish.
Awais786
An exe for a Visual C# project is created when the project is built. You can find it in either the bin/Debug or bin/Release directories under the main project directory. Probably you'll find it in bin/Debug.
As for your SQL Server question, compiling the code used to create a new table is not the same as having the code execute without an error. As was already mentioned, a sample of the code you're using will help us identify the problem.