Showing posts with label key. Show all posts
Showing posts with label key. Show all posts

Saturday, March 31, 2012

Table structure from database.

Hi,

Is it possible to retrieve in C# the table structure (primary key, type of data, ...) ?

Thanks a lot.

Sébfrom what database?
from sql server 2000 for example ...
From sql server sir :)
I am not sure that my suggests will solve your problems,
I think that you should write a Sql statement as follow:

ALTER DATABASE database
{ ADD FILE < filespec > [ ,...n ] [ TO FILEGROUP filegroup_name ]
| ADD LOG FILE < filespec > [ ,...n ]
| REMOVE FILE logical_file_name
| ADD FILEGROUP filegroup_name
| REMOVE FILEGROUP filegroup_name
| MODIFY FILE < filespec >
| MODIFY NAME = new_dbname
| MODIFY FILEGROUP filegroup_name {filegroup_property | NAME = new_filegroup_name }
| SET < optionspec > [ ,...n ] [ WITH < termination > ]
| COLLATE < collation_name >
}

SqlClient.ExcuteNonQuery(......);
SQL server 2000 why ?

Thanks

Séb
I'm interested in the structure of Access and SQL databases

TableAdapter Insert (Primary Key)

Hi

I have just started to learn ASP.Net. However I have some experience with ASP.

Anyway I have created a asp-form which should create a new entry in the database after you have clicked the submit button.

I created a tableadapter and following simple code:
tbUsersTableAdapter topAdapter=new tbUsersTableAdapter();
topAdapter.InsertUser(DateTime.Now, DateTime.Now, DateTime.Now,true,false, txtNickname.Text, 2, txtEMail.Text, txtPassword.Text,"");

Here is the SQl Command without the primary key:
INSERTINTO[tbUsers] ([CDate], [MDate], [ADate], [Active], [Activated],[Nickname], [Role],Email, [Password],[IP])VALUES (@dotnet.itags.org.CDate, @dotnet.itags.org.MDate, @dotnet.itags.org.ADate, @dotnet.itags.org.Active, @dotnet.itags.org.Activated, @dotnet.itags.org.Nickname, @dotnet.itags.org.Role, @dotnet.itags.org.eMail, @dotnet.itags.org.Password, @dotnet.itags.org.IP)

This works fine as long as I put the ID (Primary Key) into the Insert command. But I don't know how I can find out the next avaiable primary key. I have thought it would be automatically incremented. Anyway I went to the properties of the tableadapter and there was a property which I switched on for my primary key field "AutoIncrement". However it still doesn't work.
Before I used to work with MS Access and OleDB Connection. There I just skipped the Primary Key Value and it has been created automatically. Here I get an error message that the primary key can't be null.

I hope somebody could help me with that or has an idea what I'm doing wrong.

thx

Hi

I searched and tried out a lot of things. Finally I found the problem today. I had to open the table with the Server Explorer. Actually I set my ID field to Primary Key but I forgot to set the Identity Column. After I set the Identity Column to my ID field it worked... great;-)))) Now I can just add a new record with skipping the Primary Key and it will be generated automatically.


thx all

Thursday, March 22, 2012

Tags inside value field of appsettings in web.config

i need to write a xml data inside the value field in web.config file.
it looks likes this

<configuration>
<appSettings>
<add key="MyXmlData" value="<data><type></type>......." />
</appSettings>
</configuration
but i get an error message

some one help meYou need to encode/escape the characters. You can do it manually if you
know all of the rules, but I wrote a little utility for myself that I
know will do it right. I guess I should post the full app at some point,
but the relevant method is:

public string Encode(string input)
{
StringBuilder output = new StringBuilder();
using (StringWriter stringWriter = new StringWriter(output,
CultureInfo.InvariantCulture))
{

XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartElement("element");
xmlWriter.WriteAttributeString("attribute", input);
xmlWriter.WriteEndElement();
xmlWriter.Close();
}
return output.ToString();
}

Just create a simple WinForms app with a textbox to past a value into, a
button that runs the Encode method, and then a textbox for the output
(not label - you want to be able to select the output for copy/paste).

Joshua Flanagan
http://flimflan.com/blog