Sorry, I should have posted my error messages when I posted. I finally got it to work after a couple more hours of prodding and poking. :-) My connection string was off.
asp.net can be more powerful than php for sure but it seems so unforgiving and with a steep learning curve...it can be very frustrating at times and it seems much harder to find a straightforward tutorial or example online.
For the sake of anyone else that is trying to do this, below is my code (not finalized but hopefully you can make out whats going on so far) This basically connects to a sql database and displays the contents of 2 columns in a datagrid. (Code is all inline in this example).
// Create a connection to the SQL database
SqlConnection myConnection = new SqlConnection("Server=WWW2\\WWW2;Database=cpqdb;Uid=xxxxxx;Pwd=xxxxxxxxx");
// Connect to the SQL database using a SQL SELECT query to get all
// the data from the table.
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT " +
" UserName, UserPhone FROM tUsers ORDER BY UserName", myConnection);
// Create and fill a DataSet.
DataSet ds = new DataSet();
myCommand.Fill(ds);
// Bind MyDataGrid to the DataSet. MyDataGrid is the ID for the
// DataGrid control in the HTML section.
DataView source = new DataView(ds.Tables[0]);
MyDataGrid.DataSource = source;
MyDataGrid.DataBind();
}
</script>
<body>
<form id="Form1" method="post" runat="server">
<%-- Display the DataGrid information in the body of the page. --%>
<%-- Display the data in a DataGrid. --%>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#dddddd"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="10pt"
HeaderStyle-BackColor="#bbbbbb"
EnableViewState="false"
/>
</form>
</body>
</html>
Hello all:
This is my first time connecting to a database and displaying data with ASP.NET/MS SQL and I am having a very hard time getting anywhere. I've looked at tons of pages but I get errors I don't understand etc. I'm having a hard time finding a really simple, straightforward example.
All I need to do is connect to a database and just display the date in that database.
According to Visual Web Developer 2005, this is my connection string: Data Source=WWW2\WWW2;Initial Catalog=cpqdb;Persist Security Info=True;User ID=cpqpass
I can open and view the data in VWD 2005. I'm just stuck after that point. (I'm only using VWD for the above, sticking to Dreamweaver for the rest...but I would use either if it will give a working example I can study and understand. I'm used to doing this in PHP/MySQL but I feel lost here.
Can someone give me a really simple tutorial for displaying all of the data out of the table "info" in the above database? Or point me to a good tutorial for a .net newbie?
/blush.gif" style="vertical-align:middle" emoid=":blush:" border="0" alt="blush.gif" />
Thanks,
Chris
Chris Cummings
Integrity Web Development
Chattanooga Web Service