INSERT RECORD WITH HASHTABLE USING ASP.NET

Posted by Sf_Hussain786 under ASP.NET on 7/26/2012 | Points: 10 | Views : 1461 | Status : [Member] | Replies : 0
HY ALL,

I Want to insert a record in database using hashtable , i want to do all table columns in hashtable , i want to make a function which parameter
is hashtable and when i make a hashtable and add values ( all tables fields) and give parameter (hashtable) to this function .

Thankx in advance

I can insert record like this but its not a dynamiclly i want one function for all table insert record .

public void Insert_record(string Tablename, string WebName, string WebLink, string WebTitle, string WebDescription, string WebComments, string WebCategory, string CreatedOn)
{
string InsertSQL;
InsertSQL = "INSERT INTO";
InsertSQL += Tablename + "(";
InsertSQL += "WebName, WebLink, WebTitle, WebDescription, WebComments, WebCategory, CreatedOn) ";
InsertSQL += "VALUES (";
InsertSQL += "@WebName, @WebLink, @WebTitle, @WebDescription, @WebComments, @WebCategory, @CreatedOn)";

using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(InsertSQL, conn);

//cmd.Parameters.AddWithValue("@WebID", WebID);
cmd.Parameters.AddWithValue("@WebName", WebName);
cmd.Parameters.AddWithValue("@WebLink", WebLink);
cmd.Parameters.AddWithValue("@WebTitle", WebTitle);
cmd.Parameters.AddWithValue("@WebDescription", WebDescription);
cmd.Parameters.AddWithValue("@WebComments", WebComments);
cmd.Parameters.AddWithValue("@WebCategory", WebCategory);
cmd.Parameters.AddWithValue("@CreatedOn", CreatedOn);

int added = 0;

try
{
conn.Open();
added = cmd.ExecuteNonQuery();
Console.WriteLine("Record Added");
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
finally
{
conn.Close();
}
}

}

sf_hussain786


Responses

(No response found.)

Login to post response