473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Generic Database tool?

I'm new to .Net and need to create a generic (free) way to update lookup
tables in SQL Server (using C#) in ASP.Net pages. I found an article at:
http://www.dotnetjunkies.com/Tutoria...0B0429881.dcik
which explains how this can be done but does not supply enough example code
my newbie self to go through in detail where I understand it. So, does
anyone have some example code I could use to accomplish this or know where I
can find something to get me started?

Thanks,
Jeff
Nov 18 '05 #1
3 1854
".Net Newbie" <jc******@hotmail.com> wrote in message
news:uG*************@TK2MSFTNGP09.phx.gbl...
I'm new to .Net and need to create a generic (free) way to update lookup
tables in SQL Server (using C#) in ASP.Net pages. I found an article at:
http://www.dotnetjunkies.com/Tutoria...0B0429881.dcik which explains how this can be done but does not supply enough example code my newbie self to go through in detail where I understand it. So, does
anyone have some example code I could use to accomplish this or know where I can find something to get me started?


Not sure what you mean by "generic (free)" - if you've got Visual Studio,
you've got all the tools you need to interface with SQL Server. What is it
that you actually need? Do you know how SQL works? Do you know how to write
stored procedures? Do you need to create the database and its objects
yourself, or is it already created for you?

Nov 18 '05 #2
TJS
http://www.microsoft.com/downloads/d...displaylang=en

".Net Newbie" <jc******@hotmail.com> wrote in message
news:uG*************@TK2MSFTNGP09.phx.gbl...
I'm new to .Net and need to create a generic (free) way to update lookup
tables in SQL Server (using C#) in ASP.Net pages. I found an article at:
http://www.dotnetjunkies.com/Tutoria...0B0429881.dcik which explains how this can be done but does not supply enough example code my newbie self to go through in detail where I understand it. So, does
anyone have some example code I could use to accomplish this or know where I can find something to get me started?

Thanks,
Jeff

Nov 18 '05 #3
Sorry I was so vague with my question. I am experienced with SQL Server but
fairly new to .Net. Anyway, here's the gist of my problem. I have a number
of small tables in SQL Server and want to write an aspx page that will allow
users to select a table from a list, populate a datagrid (or other control,
datatable, etc) with the rows from that table and update, add, delete
records. I want to write it so that as I specify new tables that the users
can access, the code, datagird and the update/delete/ inserts adjust
according to the selected table which will have a varying number of columns.
I have already created part of the page which allows displays the data from
the available tables in the datagrid (with an editcolumn), however I do not
know how to put together the update/add/deletes so that they are generic
enough to work for any table I select. In addition, most of my lookup
tables have a key that is an Identity column that I do not want to allow the
user to change (but need to retain for updates).

Basically I want to write an scaled down ASP.Net version of the tool on
www.genericdb.com. I could write something specific for each table to allow
adds/updates/deletes as I would a normal datagrid similar to the QuickStart
samples, but obviously want to avoid this as I may have to adjust or
replicate code whenever I add a new lookup table to the list.

My code so far is as follows:

<%@ Control Language="C#"
Inherits="ASPNET.StarterKit.Portal.PortalModuleCon trol" %>
<%@ Register TagPrefix="Portal" TagName="Title"
Src="~/DesktopModuleTitle.ascx" %>
<%@ Register TagPrefix="cc1" Namespace="StrengthControls.Scrolling"
Assembly="StrengthControls.Scrolling" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<script language="C#" runat="server">
//################################################## ########################
#####################
// Common strings/variables used throughout the procedure
//################################################## ########################
#####################
public SqlConnection con = new
SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
public DataSet myDataSet = new DataSet();
String SQLStatement = null;
//################################################## ########################
#####################
// Clears the DataGird when the page loads initially
//################################################## ########################
#####################
void Page_Load(Object sender, EventArgs e) {
if(!IsPostBack) {
}
}
//################################################## ########################
#####################
// Calls the function that populates the DataGird when a linkbutton is
clicked and sets the
// title label based on the Table selected
//################################################## ########################
#####################
void SelTable(Object sender, CommandEventArgs Args) {
Title.Text = "Data for Table: " + Args.CommandName;
ViewState["SelTbl"] = Args.CommandName.ToString();
BindGrid();
}
//################################################## ########################
#####################
// Function to Edit the DataGrid
//################################################## ########################
#####################
void DataGrid1_Edit(Object obj, DataGridCommandEventArgs e){
DataGrid1.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}
//################################################## ########################
#####################
// Function to Update the DB information from the DataGrid
//################################################## ########################
#####################
void DataGrid1_Update(object source, DataGridCommandEventArgs E) {
string Identity = (E.Item.Cells[1]).Text;
// ?????????????????????????????????????????????????? ????????????
// ?????????????????????????????????????????????????? ????????????
// ?????????????????????????????????????????????????? ????????????
}
//################################################## ########################
#####################
// Function to Cancel the Update from the DataGrid
//################################################## ########################
#####################
void DataGrid1_Cancel(Object obj, DataGridCommandEventArgs e) {
DataGrid1.EditItemIndex = -1;
BindGrid();
}
//################################################## ########################
#####################
// Function to Bind the Data to the Datagrid when it is populated from the
Database
//################################################## ########################
#####################
void BindGrid(){
DataGrid1.DataSource=GetData().Tables["xxx"].DefaultView;
DataGrid1.DataBind();
}
//################################################## ########################
#####################
// Dataset populated from the Select Statement called from the Databind
//################################################## ########################
#####################
private DataSet GetData(){
SQLStatement="Select * FROM " + ViewState["SelTbl"];
SqlDataAdapter myCommand = new SqlDataAdapter(SQLStatement, con);
myCommand.Fill(myDataSet, "xxx");
return myDataSet;
}
</script>
<html>
<head>
<style>
..links {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;
font-weight: bold; color: #660000; height="18"
}
..title{FONT-FAMILY: Verdana; FONT-WEIGHT: 600; FONT-SIZE: 14;
text-decoration:underline;}
</style>
</head>
<body bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0"
marginheight="0" marginwidth="0">
<cc1:SmartScroller id="SmartScroller1" runat="server" />
<portal:title runat="server" />
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody>
<tr>
<td width="150" valign="top" rowspan="2">
<span class="links"><asp:LinkButton runat="server" id="Departments"
Text="Departments" CommandName="Departments" OnCommand="SelTable"
/></span><br />
<span class="links"><asp:LinkButton runat="server" id="ProjectTypes"
Text="ProjectTypes" CommandName="ProjectTypes" OnCommand="SelTable"
/></span><br />
<span class="links"><asp:LinkButton runat="server" id="ProjectStatuses"
Text="ProjectStatuses" CommandName="ProjectStatuses" OnCommand="SelTable"
/></span><br />
<span class="links"><asp:LinkButton runat="server" id="Services"
Text="Services" CommandName="Services" OnCommand="SelTable" /></span><br />
</td>
<td valign="top">
<asp:Label runat="server" id="Title" cssclass="title" /><br />
</td>
</tr>
<tr>
<td valign="top">
<asp:DataGrid id="DataGrid1" cellpadding="4" BackColor="#EEDDEE"
runat="server"
GridLines="None" BorderWidth="1px" BorderColor="DarkSlateBlue"
ForeColor="Black"
Font-Size="8pt"
OnEditCommand="DataGrid1_Edit"
OnUpdateCommand="DataGrid1_Update"
OnCancelCommand="DataGrid1_Cancel"
<FooterStyle backcolor="Tan" />
<HeaderStyle font-bold="True" backcolor="DarkSlateBlue"
ForeColor="white" />
<PagerStyle horizontalalign="Center" forecolor="DarkSlateBlue"
backcolor="#CCC7E5" />
<SelectedItemStyle forecolor="GhostWhite" backcolor="DarkSlateBlue" />
<AlternatingItemStyle backcolor="#CCC7E5" />
<Columns>
<asp:EditCommandColumn
EditText="<img src='/PortalCSSDK/images/edit.gif' border='0'
alt='Edit' />"
CancelText="Cancel"
UpdateText="Update"
Itemstyle-Wrap="False"
HeaderText="Edit" />
</Columns>
</asp:DataGrid>
<asp:Label runat="server" id="Message" />
</td>
</tr>
</tbody>
</table>
</body>
</html>

Any suggestions, recommendations, changes, rewrites, useful links, etc would
be greatly appreciated.

Thanks,
Jeff

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:ez**************@TK2MSFTNGP11.phx.gbl... ".Net Newbie" <jc******@hotmail.com> wrote in message
news:uG*************@TK2MSFTNGP09.phx.gbl...
I'm new to .Net and need to create a generic (free) way to update lookup
tables in SQL Server (using C#) in ASP.Net pages. I found an article at:

http://www.dotnetjunkies.com/Tutoria...0B0429881.dcik
which explains how this can be done but does not supply enough example

code
my newbie self to go through in detail where I understand it. So, does
anyone have some example code I could use to accomplish this or know

where I
can find something to get me started?
Not sure what you mean by "generic (free)" - if you've got Visual Studio,
you've got all the tools you need to interface with SQL Server. What is it
that you actually need? Do you know how SQL works? Do you know how to

write stored procedures? Do you need to create the database and its objects
yourself, or is it already created for you?

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: mountain man | last post by:
Greetings to all database professionals and laymen, Let us make a bold assumption that we have developed a software tool for the SQL Server environment which simply acts as an interface between...
3
by: SimonH | last post by:
Hi all, I would like to make a generic set of methods that could be called regardless of the database behind the scenes. One of the methods I would like would take a string sql statement and...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
4
by: Jonas Hei | last post by:
I've noticed that one can use IE to test web pages (by going on http://hostname/blah/blah.asmx - and then it shows a list of methods supported by the webservice, and on selecting each method once...
18
by: Rune B | last post by:
Hi Group I was considering using a Generic Dictionary<> as a value container inside my business objects, for the reason of keeping track of fields changed or added and so on. - But how...
5
by: DelphiAddict | last post by:
Hi. Has anyone looked into generic factoring for making database independant applications? (Framework 2.0) I have, but I'm in the starting fase. What I do know is that if you only write...
3
by: markww | last post by:
Hi, I have a wrapper around some 3rd party database library function. The pseudo code looks like the following - it is meant to open a table in a database, extract values from a table, then copy...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
1
by: jimenezkrause | last post by:
Hello, I administrate a large number of Oracle databases for my company. Some DBs are easily structured and the staff responsible for keeping them updated are able to use an Oracle client...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.