updating teradata through asp.net

Connectivity
Enthusiast

updating teradata through asp.net

hello. i am able to connect to Teradata through my asp.net application, however i can only "select" from the database. does anyone know how to use parameters in my code behind so that i can update and insert information?
here is what i have for just selecting data. what am i missing to allow me to insert or update with parameters? i do not have write access for stored procedures in teradata so my queries have to be in a query string in the code behind.

public static DataSet getGroupList()
{
TdConnection cn = new TdConnection();
TdConnectionStringBuilder conStrBuilder = new TdConnectionStringBuilder();
conStrBuilder.DataSource = "Example";
conStrBuilder.Database = "ExampleDB";
conStrBuilder.UserId = "ExampleUser";
conStrBuilder.Password = "ExamplePW";
cn.ConnectionString = conStrBuilder.ConnectionString;
cn.Open();

TdCommand cmd = cn.CreateCommand();
cmd.CommandText = "select Group_Descrip from ExampleDB.ExampleTable";

DataSet ds = new DataSet();

TdDataAdapter da = new TdDataAdapter(cmd);
da.Fill(ds);

return(ds);
}

thank you,
Tim
4 REPLIES
Teradata Employee

Re: updating teradata through asp.net

Hello,

All you have to do is to change the command text in following:

cmd.CommandText = "select Group_Descrip from ExampleDB.ExampleTable";

Example:

cmd.CommandText = "UPDATE Table1 SET Col1 = 1 WHERE ID = 1;";

Are you getting some sort of error, or what exactly you are trying to do?

Regards,

Adeel
Enthusiast

Re: updating teradata through asp.net

no error, jsut wanted to know how to code it cause i have a parameteri have to pass into it, dont know how. any help?
Teradata Employee

Re: updating teradata through asp.net

For that you can use query as follows:

cmd.CommandText = "UPDATE "+ txtTableName +" SET "+ txtColumnName +" = "+ numValue +" WHERE ID = 1;";

This can cause SQL injection attacks possible, which you can avoid by parsing the input variables before putting them as command string.

(This is more of a ASP.NET question rather than Teradata!)

Regards,

Adeel
Teradata Employee

Re: updating teradata through asp.net

.NET Data Provider for Teradata ships with Learning Examples. They are in \samples\LearningExamples directory. Review readme.doc first.