asp conversion to c# - Urgent

Hi

I am a newbie to c# and really urgently need this piece of code which is embeded into a web page converted to c#

thanks

<%       
dim i
sql ="SELECT parent,mName,mLink,menuorder from tblMenu where parent=1 ORDER BY menuorder ASC"
Set headerrs = Server.CreateObject("ADODB.Recordset")
headerrs.Open sql, conn, 3, 3
i=0
If (headerrs.RecordCount > 0) Then
         while not headerrs.eof
      Response.write("oCMenu.makeMenu('sub0" & i & "','top0','" & headerrs.fields("mName") & "','" & headerrs.fields("mLink") & "')" & vbcrlf)
      i=i+1                                          
      headerrs.movenext
           wend
end if
      
headerrs.close
%>
caffermAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:
Hi,

just define SqlConnection with as cn, and try this code

string sql ="SELECT parent,mName,mLink,menuorder from tblMenu where parent=1 ORDER BY menuorder ASC";
                  int i=0;
                  SqlCommand cmd= new SqlCommand(sql,cn);
                  SqlDataReader dr;
                  cn.Open();
                  dr = cmd.ExecuteReader (CommandBehavior.CloseConnection);
                  if (dr.HasRows )
                  {
                        while (dr.Read())
                        {
                              Response.Write("oCMenu.makeMenu('sub0" + i.ToString() +
                              "','top0','" + dr["mName"] +
                                    "','" + dr["mLink"] + "')" +"\n");
                                    i++;
                        }
                  }

HTH

Regards,
Mohammed

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caffermAuthor Commented:
Nice one - thanks very much

Matt
Mohammed NasmanSoftware DeveloperCommented:
Glad to help you Matt :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.