Visual Studio .NET - getting a value - Asked By Gabriel Kralicz on 20-Jul-14 01:49 PM

I need help with this -> how can I get a value from DB <sql> into a variable?
Exists something like in old ASP? :
dim myvar as string
.
.
.
myvar = <<sql>>
<%=myvar%></sql></sql>

Try this: - Asked By Peter Bromberg on 26-Nov-01 11:25 AM

<%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.SqlClient" %>
  
  protected void Page_Load(object sender, EventArgs e)
  {
      string strMyVar;
    DataSet ds = new DataSet();
    SqlConnection strConn = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");
    SqlDataAdapter SQLDa = new SqlDataAdapter("SELECT TOP 1 CompanyName FROM Customers", strConn);
    SQLDa.SelectCommand.Connection.Open();
    SQLDa.Fill(ds, "Customers");
    strMyVar= ds.Tables[0].Rows[0]["CompanyName"].ToString();
    Customer.Text =strMyVar;
   }
  
  
  
   <form runat="server">
  <H3>Result:</H3>
  <asp:label runat="server" id="Customer"    />
  </form>

thanks! - Asked By Gabriel Kralicz on 27-Nov-01 04:38 AM

I´ll test this code later, here at my work I´ve got a very weak PC...