hi i have i similar problem.
i have 2 problems and i'm stuck. can somebody please help me, because if somebody don't hepl me i don't
know what to do. it's emergency!!! :-(
Firt i thank all of you for your time!!!
The code is in C# and the database is Oracle.
I'll try to explain exactlly the problem.
1-st Problem-Dynamic Links
please look the database table "field" first.
I need to create dynamiclink.
first i call the DynamicLinks() function whitch create LinkButtons (they stay always the same on Pannel3) named from the database and
their OnClick method does call an artikel from the database with the function GetArtikel (ArtikelName) and should creates
other LinkButtons (on Panel3), but it does not, it does after i click twice (on the second click). the same problem is for
the Linkbuttons on Panel3 (they call artikel from the database and create other linkbutton on Panel3 related to the clicked
Button), i must click them twice to appear the changes.
i hope that i explained good the problem, my english in not so good. i post the code, it's a bit long, i've put the unnecessary code away.
The second Problem is described after the code. Please read it also!!!
Here is the oracle table:
Code:
create table field (
name varchar2(20),
upperfield varchar2(20),
primary key (name),
foreign key (upperfield) references field(name),
unique(name,upperfield));
Here is the C# code:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
Connection();
DynamicLinks();
DynamicLinks(Label6.Text);
}
else
{
DynamicLinks();
DynamicLinks(Label6.Text);
connection.Close();
}
}
private void DynamicLinks(string field)
{
prm1 = cmd.Parameters.Add("pField",OracleDbType.Varchar2);
prm1.Value = field;
OracleDataReader reader;
cmd.CommandText = "SELECT count(*) as Anzahl FROM field WHERE upperfield = :pField";
Anzahl = Convert.ToInt32(reader["Anzahl"]);
cmd.CommandText = "SELECT name FROM field WHERE upperfield = :pField";
LinkButtons1 = new LinkButton[Anzahl];
string [] fields = new string[Anzahl];
while(reader.Read())
{
fields[i] = reader["name"].ToString();
i++;
}
for (i = 0; i< Anzahl; i++)
{
LinkButtons1[i] = new LinkButton();
LinkButtons1[i].Text = fields[i];
LinkButtons1[i].Click += new EventHandler(this.LinkButtons1_Click);
Panel1.Controls.Add(LinkButtons1[i]);
Panel1.Controls.Add(new LiteralControl("<br>"));
}
}
private void DynamicLinks()
{
cmd.CommandText = "SELECT count(*) as Anzahl FROM field WHERE upperfield IS NULL";
Anzahl = Convert.ToInt32(reader["Anzahl"]);
cmd.CommandText = "SELECT name FROM field WHERE upperfield IS NULL";
LinkButtons = new LinkButton[Anzahl];
string [] fields = new string[Anzahl];
while(reader.Read())
{
fields[i] = reader["name"].ToString();
i++;
}
for (int j = 0; j< Anzahl; j++)
{
LinkButtons[j] = new LinkButton();
LinkButtons[j].Text = fields[j];
LinkButtons[j].Click += new EventHandler(this.LinkButtons_Click);
Panel3.Controls.Add(LinkButtons[j]);
Panel3.Controls.Add(new LiteralControl("<br>"));
}
}
private void LinkButtons_Click(object sender, System.EventArgs e)
{
for (int i = 0; i<LinkButtons.Length;i++)
{
if (sender.GetHashCode() == LinkButtons[i].GetHashCode())
{
Connection();
Label1.Text = GetArtikel(LinkButtons[i].Text);
Label2.Text = LinkButtons[i].Text;
Label6.Text = LinkButtons[i].Text;
}
}
DynamicLinks();
}
private void LinkButtons1_Click(object sender, System.EventArgs e)
{
for (int i = 0; i<LinkButtons1.Length;i++)
{
if (sender.GetHashCode() == LinkButtons1[i].GetHashCode())
{
Connection();
Label1.Text = GetArtikel(LinkButtons1[i].Text);
Label2.Text = LinkButtons1[i].Text;
Label6.Text = LinkButtons1[i].Text;
}
}
DynamicLinks(Label6.Text);
}
2-nd Problem
I want to call an oracle stored procedure, but i don't know how.
i call it like this but is does not work.
Code:
OracleCommand cmd1 = new OracleCommand("PATH",connection);
cmd1.CommandType = CommandType.StoredProcedure;
OracleParameter p1 = cmd1.Parameters.Add("field",OracleDbType.Varchar2);
p1.Direction = ParameterDirection.Input;
cmd1.Parameters["field"].Value = "example";
cmd1.ExecuteNonQuery();
OracleDataReader reader1 = (OracleDataReader) p1.Value;
the procedure is declared like this:
CREATE FUNCTION Path(field IN VARCHAR2) RETURN VARCHAR2
THANKS TO ALL OF YOU.
TONI