Add an AutoNumber column as primary key field in Access (2003/7) through DDL
Posted: December 14, 2009 Filed under: Access 2007 1 CommentAlter TABLE XYZ
Add column myID COUNTER CONSTRAINT PrimaryKey PRIMARY KEY
If we want to set the seed for the AutoNumber field, we can run this query:
alter table XYZ
alter column myID Counter(1000,1);
There is a documnet from Microsoft to demostrate:
How to Create and Drop Tables and Relationships Using SQL DDL
refer to this link: http://support.microsoft.com/?id=116145
You can also find more information on this topic from this document:
(How to use common Data Definition Language (DDL) SQL statements for the Jet database engine)
http://support.microsoft.com/default.aspx?scid=kb;en-us;180841
Radiobuttonlist with a tooltip context from database
Posted: December 4, 2009 Filed under: ASP.NET 2 Leave a commentHere is a link of the style you will use for your tooltips:
http://jlhaslip.trap17.com/samples/tooltips/index.html
Here is the CSS style from the link:
You need to add a hyperlink and define a <span> tag for the tooltip text of your RadiobuttonList in your code:
string myLink = "<a href=\"#\" class=\"info\">" + rblReader_ChangeTypes["Name"].ToString() + "<span>"+rblReader_ChangeTypes["ToolTip"].ToString()+"</span></a>"
;
The code block:
SqlConnection sqlConn1 = new SqlConnection(connectionString);
SqlCommand sqlCmd_GetChangeTypes = new SqlCommand("Select ID, Name, tooltip FROM [aTable]", sqlConn1);
sqlConn1.Open();
SqlDataReader rblReader_ChangeTypes = sqlCmd_GetChangeTypes.ExecuteReader();
if (rblReader_ChangeTypes.HasRows)
{
while (rblReader_ChangeTypes.Read())
{
string myLink = "<a href=\"#\" class=\"info\">" + rblReader_ChangeTypes["Name"].ToString() + "<span>"+rblReader_ChangeTypes["ToolTip"].ToString()+"</span></a>";
ListItem li = new ListItem(myLink, rblReader_ChangeTypes["ID"].ToString());
//li.Attributes.Add("title", rblReader_ChangeTypes["ToolTip"].ToString());
//li.Attributes.Add("class", "info");
li.Attributes.Add(
"ID", rblReader_ChangeTypes["ID"].ToString());
rblChangeType.Items.Add(li);
//Source for Tooltip
// http://jlhaslip.trap17.com/samples/tooltips/index.html
}
rblChangeType.SelectedIndex = 0;
}
else
{
// logic for no rows had been returned
}
rblReader_ChangeTypes.Close();
sqlConn1.Close();
Bulk Insert to load text data file to SQl Server with Format File
Posted: December 3, 2009 Filed under: SQL Server 2005 1 Commentbcp mydb
..Book1SkipOneColumn format nul –f Default.xml –c –x –TFormat file in non-XML format:
bcp mydb..Book1 format nul –f Default2.fmt –c –T
You can find more information about format file here: http://technet.microsoft.com/en-us/library/ms190393.aspx
By using a format file, you can skip a table column or skip a data column or mapping columns between data file and the table. You can find some sample from this link: http://technet.microsoft.com/en-us/library/ms190396.aspx
It seems the syntax in the sample will not work with file extension .csv file but I need to get a confirmation on this later.
I have included a sample ASP.NET page through a button click to upload a text data file to SQL Server 2005:
protected void Button2_Click(object sender, EventArgs e)
{
string ConnectionString = ConfigurationManager.ConnectionStrings["forumConnectionString"].ToString();
SqlConnection con = new SqlConnection(ConnectionString);
using (SqlCommand cmdInsert = new SqlCommand(@"BULK INSERT myTestSkipCol FROM ‘C:\datatest\Book1Noheader2.txt’ WITH (FORMATFILE = ‘C:\datatest\Default2.fmt’)", con))
{
con.Open();
cmdInsert.ExecuteNonQuery();
con.Close();
}
}
Another one without format file:
protected void Button1_Click(object sender, EventArgs e)
{
string ConnectionString = ConfigurationManager.ConnectionStrings["test_for_forumConnectionString"].ToString();
SqlConnection con = new SqlConnection(ConnectionString);
using (SqlCommand cmdInsert = new SqlCommand(@"BULK INSERT Book1 FROM ‘C:\datatest\Book1.csv’ WITH (FIRSTROW = 2, FIELDTERMINATOR = ‘,’, ROWTERMINATOR = ‘\n’)", con))
{
con.Open();
cmdInsert.ExecuteNonQuery();
con.Close();
}
}