|
nclauder wrote: private void Fill()
{
DataTable table = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from dbo.DashBoard", con);
adapter.Fill(table);
}
private void Bind()
{
DataTable table = new DataTable();
dgis.DataSource = table;
dgis.DataBind();
}
private void InsertEmpty()
{
DataTable table = new DataTable();
table.Rows.InsertAt(table.NewRow(), 0);
}
You create a new datatable everytime you do anything which means that when you bind you have nothing in it. You should create it in the originating method and pass it to the three functions as a ByRef variable or create a module level variable.
CleAkO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
Thanks,
The problem still not solved. The row cannot be inserted yet another problem is when I run the form one row from the database converts itself into two rows in the datagrid. what would be the problem? My code now looks like this:
DataTable table = new DataTable();
private DataTable Fill()
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from dbo.DashBoard", con);
adapter.Fill(table);
dgis.DataSource=table;
dgis.DataBind();
return table;
}
private void Bind()
{
dgis.DataSource = Fill();
dgis.DataBind();
}
private void InsertEmpty()
{
table.Rows.InsertAt(table.NewRow(),0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{
// inserting
dgis.EditItemIndex = 0;
// modify text
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
// fill table, insert empty row, bind to datagrid
Fill();
InsertEmpty();
Bind();
//dgis.DataBind();
}
private void dgis_ItemCommand(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// stop editing
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;
case "Update":
break;
case "Cancel":
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
break;
case "Edit":
// begin editing
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}
// fill and bind
Fill();
Bind();
}
|
|
|
|
|
nclauder wrote: private void Bind()
{
dgis.DataSource = Fill();
dgis.DataBind();
}
private void InsertEmpty()
{
table.Rows.InsertAt(table.NewRow(),0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{
// inserting
dgis.EditItemIndex = 0;
// modify text
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
// fill table, insert empty row, bind to datagrid
Fill();
InsertEmpty();
Bind();
//dgis.DataBind();
}
You are setting the .DataSource = Fill(); but then in the Fill() you are setting the .DataSource and .DataBind . You are also inserting the row after the initial bind so you are sort of repeating steps unnecessarily.
Try this.
DataTable table = new DataTable();
private DataTable Fill(){
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from dbo.DashBoard", con);
adapter.Fill(table);
return table;
}
private void Bind(){
dgis.DataSource = Fill();
dgis.DataBind();
}
private void InsertEmpty(){
table.Rows.InsertAt(table.NewRow(),0);
}
private void bttnew_Click(object sender, System.EventArgs e){
dgis.EditItemIndex = 0;
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
Fill();
InsertEmpty();
Bind();
} Why are you inserting an empty row when you begin editing? You should be able to just read in that row on the datagrid and add it to the datatable after the editing is finished. Check out http://www.datagridgirl.com[^].
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
Thanks cleako,
This has solved the problem of one row multiplying into two. But I still press a button and it does not return a new column. I've writen the code for insert but still no change?
DataTable table = new DataTable();
private DataTable Fill()
{
SqlDataAdapter adapter = new SqlDataAdapter("select * from dbo.DashBoard", con);
adapter.Fill(table);
return table;
}
private void Bind()
{
dgis.DataSource = table;
dgis.DataBind();
}
private void InsertEmpty()
{
table.Rows.InsertAt(table.NewRow(), 0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{
// inserting
dgis.EditItemIndex = 0;
// modify text
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
// fill table, insert empty row, bind to datagrid
Fill();
InsertEmpty();
Bind();
}
private void dgis_ItemCommand(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// stop editing
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
System.Web.UI.WebControls.TextBox st=new System.Web.UI.WebControls.TextBox();
st=(System.Web.UI.WebControls.TextBox)e.Item.Cells[5].FindControl("txtobjach");
System.Web.UI.WebControls.TextBox st1=new System.Web.UI.WebControls.TextBox();
st1=(System.Web.UI.WebControls.TextBox)e.Item.Cells[4].FindControl("txtobj");
System.Web.UI.WebControls.TextBox st2=new System.Web.UI.WebControls.TextBox();
st2=(System.Web.UI.WebControls.TextBox)e.Item.Cells[3].Controls[0];
System.Web.UI.WebControls.TextBox st3=new System.Web.UI.WebControls.TextBox();
st3=(System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0];
System.Web.UI.WebControls.TextBox st4=new System.Web.UI.WebControls.TextBox();
st4=(System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0];
System.Web.UI.WebControls.TextBox st5=new System.Web.UI.WebControls.TextBox();
st5=(System.Web.UI.WebControls.TextBox)e.Item.Cells[0].Controls[0];
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into DashBoard (ObjectiveAchieved,Objective) values ('@ObjectiveAchieved' ,'@objective');";
myCommand.Parameters.Add(new SqlParameter("@ObjectiveAchieved",SqlDbType.Char,45));
myCommand.Parameters["@ObjectiveAchieved"].Value=st.Text;
myCommand.Parameters.Add(new SqlParameter("@Objective",SqlDbType.Char,45));
myCommand.Parameters["@Objective"].Value=st1.Text;
myCommand.Parameters.Add(new SqlParameter("@Workinghrs",SqlDbType.Char,45));
myCommand.Parameters["@Workinghrs"].Value=st2.Text;
myCommand.Parameters.Add(new SqlParameter("@Loggedout",SqlDbType.Char,45));
myCommand.Parameters["@Loggedout"].Value=st3.Text;
myCommand.Parameters.Add(new SqlParameter("@Loggedin",SqlDbType.Char,45));
myCommand.Parameters["@Loggedin"].Value=st4.Text;
myCommand.Parameters.Add(new SqlParameter("@MoodToday",SqlDbType.Char,45));
myCommand.Parameters["@MoodToday"].Value=st5.Text;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgis.EditItemIndex=-1;
BindDataGrid();
break;
case "Update":
break;
case "Cancel":
break;
case "Edit":
// begin editing
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}
// fill and bind
Fill();
Bind();
}
Thanks.
|
|
|
|
|
installation and usage of apache server ? sample to use apache server
Manjunath S
GESL
Bangalore
|
|
|
|
|
What is it you want?
Brad
Australian
- Captain See Sharp on "Religion"
any half intelligent person can come to the conclusion that pink unicorns do not exist.
|
|
|
|
|
I am working on a basic internal site, I just added a new simple page that fills a simple DataGrid with data from a SQL table, aside from the conversion issue reference below all seemed to go smooth until I tried to deploy it.
when I try to run it on teh server I get teh error:
"File or Assembly name CrystalDecisions.CrystalReports.Engine or one of its dependancies was not found"
I appears there is a new entry in my web.config file as follows. The portion after compilation, default language and debug="true" part is new.
<compilation defaultlanguage="vb" debug="true"><assemblies><add assembly="CrystalDecisions.CrystalReports.Engine, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"><add assembly="CrystalDecisions.ReportSource, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"><add assembly="CrystalDecisions.Shared, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"><add assembly="CrystalDecisions.Web, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304">
If I try to take it out I get an error, does anyone know where this came from and/or the best way to resolve the issue?
I think I did drag a Crystal Reports Viewer on teh form at one point but removed it...
Thanks in advance,
|
|
|
|
|
The correct crystel reports dlls need to installed on your web server. I have gotten this error before. If your web.config file you probably have something like this:
<assemblies>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Enterprise.Framework, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Shared, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Enterprise.InfoStore, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</assemblies>
That stuff needs to be removed if you are not using crystel reports.
Hope that helps.
Ben
|
|
|
|
|
Thanks, I tried removing it and got another error... think I messed up the syntax someplace when I removed it correctly all is well.
Thanks

|
|
|
|
|
I have a web form that a user fills out. The form fills in several tables which key off another table that I'll call Table1. When I add a record to Table2, I need a valid key from Table1. What I'm currently doing is adding a record to Table1 and using the key SQL Server returns to me. So far so good. My problem is if the user doesn't complete the form, I'll have a basically empty record in Table1 and bunch of records in Table2.
What I would do in a desktop app would be to use DataTables (C#) in memory and update the DB later but since this is a Web Form, I don't want to kill the server with a bunch of extra junk.
So is what I'm currently doing correct? Should I write a utility/query to clean out the half completed records? Am I correct in assuming that keeping a couple DataTables in memory for each logged in user is bad practice?
Thanks in advance!
|
|
|
|
|
I have a SQL database with a "Real" field called "MinutesRemining", I am trying ot load it into a DataGrid as in the example below:
<br />
Dim dt As New DataTable<br />
Dim MyDataRow As DataRow<br />
<br />
dt.Columns.Add(New DataColumn("MinutesRemaining", GetType(GetSQLInt32)))<br />
<br />
sqlStatement = "Select MinutesRemaining from tblStatusLot "<br />
<br />
Dim cmd As New SqlCommand(sqlStatement, cn)<br />
Dim dr As SqlDataReader = cmd.ExecuteReader<br />
Do While dr.Read()<br />
MyDataRow = dt.NewRow()<br />
MyDataRow(0) = dr.GetSqlInt32(0)<br />
The database field type is "Real", but there is not an option for real in the "dr." options, nor is there one in the DataColumn function options. I get an error "Specified Cast is Not Valid", when I use GetDouble, GetSQLInt32, I am not what conversion I should be usng as there is not an option for Real.
Thanks in advance...
|
|
|
|
|
Hard to know for sure, but I think what you want here is the Decimal type GetSqlDecimal. So the type in your table will also need to be of Type Decimal or float. I am pretty sure if you have a real number in sql calling it an int is not going to work.
Hope that helps.
Ben
|
|
|
|
|
Thanks for the suggestion, I changed the table and tried a few other casts. It turns out to be happiest with no casting at all... Now why did I not think if that first....
|
|
|
|
|
Great, I am glad that it worked out. Isn't that funny how it works out that way sometimes?
Ben
|
|
|
|
|
The equivalent .NET data type for a Real is Single . You can use the GetFloat method to read it from the data reader.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi,
I'm trying to Insert a new Row on a dagrid. When I did a google search, I got an example on this address: http://www.codeproject.com/ASPNET_DataGrid.asp.
I've done mycode as follows:
private void Fill()
{
DataSet ds=new DataSet();
SqlDataAdapter adapter =new SqlDataAdapter("select * from DashBoard", con);
adapter.Fill(ds);
}
private void Bind()
{
DataSet ds=new DataSet();
dgis.DataSource = ds;
dgis.DataBind();
}
private void InsertEmpty()
{
DataSet table=new DataSet();
Table.Rows.InsertAt(Table.NewRow(), 0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{
dgis.EditItemIndex = 0;
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Insert";
Fill();
InsertEmpty();
Bind();
}
private void dgis_ItemCommand(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;
case "Update":
break;
case "Cancel":
EditCommandColumn ecc =(EditCommandColumn) dgis.Columns[0];
ecc.UpdateText = "Update";
break;
case "Edit":
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}
Fill();
Bind();
}
On compiling I get this error
-'System.Web.UI.WebControls.Table' does not contain a definition for 'NewRow'
-'System.Web.UI.WebControls.TableRowCollection' does not contain a definition for 'InsertAt'
-'An object reference is required for the nonstatic field, method, or property 'System.Web.UI.WebControls.Table.Rows'
Where could I be going wrong?
|
|
|
|
|
Hi,
I want a customized User Profile Search. I cannot use GetUserProfile method as it returns only one user profile. What is the way to get a list of users matching the input user name.Please help me with the sharepoint 2007 code for the same.
Thanks in advance...........
Usha
|
|
|
|
|
hi,
i want to do keyword search in word .doc files, e.g in resumes, i want to implement a script in asp 3.0, please guide me by giving some help full links to get started, or give some code snipts... any help will be highly appreciated.
Many Thanks,
Adnan Rafiq
muhammadadnanrafiq@gmail.com
|
|
|
|
|
Hi all,
actually i am very depressed of VS.NET 2.0 i have a real problem and am sure i'll found the solution here. firstly i can't understand how .net 2.0 doesn't automatically create dll file for the project, while i was using .net 1.1 there was bin\debug which contains dll file for the web project so i can upload it on the server each time i change something in the code. now after converting to .net 2.0 i don't know what to do? also i found a tool which is "web deployment" i installed it and tried to get the dll it works once and didn't work again but when it worked the build number was 0.0.0.0 and it never changes when i make changes and build again. please i really need help if anyone can. Thank you all
|
|
|
|
|
The problem may be in your solutionInfo file. You should find something like this:
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")]
I am guessing that you don't have * in the build you just have 0.0.0.0 which means you are controling the build number.
Hope that helps.
Ben
|
|
|
|
|
Hi All,
I'm setting up a webserver and I'm a noob when it comes to. I will be doing my own research but just so I can direct my energy (and money!) on the right references, can I have your suggestions on:
1. Beginner's Guide
2. Definitive Reference
when it comes to
a. Setting up
b. Maintaining
webserver/website.
I am planning for the website to be interactive and not just plain html. Also, please don't limit your suggestions to books, websites will also be good.
Thank you and have a nice week ahead!
-- modified at 20:59 Sunday 25th February, 2007
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
Don't do it. If you are planning to create a web server that is publicly available then you will need more then just what references can teach you, you need experience. I would advise you use a hosting service to host your website and learn by example.
Also what language and platforms are you planning to use?
Brad
Australian
- Christian Graus on "Best books for VBscript"
A big thick one, so you can whack yourself on the head with it.
|
|
|
|
|
Thanks mate. I am weighing whether to use IIS/Asp.Net or Apache/Java (then there's CSS and a myriad other technologies). Since I am a C#/MS developer I have bias towards the former. I have registered a DNS but I thought if I host it myself I would learn more from it (I'll just use a dynamic DNS host). Yes I would like to do hands on hence I've bought all the necessary h/w and the DNS service but still it would be great to have some references. One that is for beginners and another definitive.
Cheers!
DC
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
Well, You are about to embark on a journey fraught with danger.
It's one thing setting up the server to run, but it's another thing when the banshee's arrive and start attacking the server, and believe me they will arrive in a matter of days, it is then that unfortunately no amount of books, references etc. will prepare you for, and you will be spending most of your time trying to figure out what they have done, instead of actually learning.
I think what you have to decide is what do you actually want to learn? To you want to learn how to code and deploy a website? Or do you want to learn how to defend a web server? Sadly learning how to do both will take plenty of time and effort.
I found this book invaluable when it came to IIS 6.0
IIS 6.0 book
|
|
|
|
|
Web development is one thing; running and securing a web server is another.
If you want to run a web server and understand how you can lock it down, instead of hosting it at a service provider, maybe the following links can point you in the right direction. Be prepared for getting some unwanted attention, and spending some time to deal with it.
http://articles.techrepublic.com.com/5100-10878_11-5055458.html
http://www.microsoft.com/technet/community/events/iis/tnt1-40.mspx
http://www.windowsecurity.com/articles/Installing_Securing_IIS_Servers_Part1.html
http://www.washington.edu/computing/support/windows/UWdomains/IISsecchecklist.html
http://searchsecurity.techtarget.com/tip/1,289483,sid14_gci1015581,00.html
If you want to just run a web server that you and a few people known to you wants to access, you can use a port other than port 80. Also make sure that only the web server port remains accessible from the Internet.
Go through the web server logs regularly. A hardware firewall may be good to have, but not essential. After all, if you have problems that take up too much of your time, you can just block the port, take down the webserver, and host it on a hosting service. It might also be a good idea to capture incoming packets (you won't have too many) using Wireshark so that you understand what kind of traffic your webserver attracts.
If you have the time, I will recommend that you do this. It will enhance your skills for sure. But, if you are interested in just getting a web presence and not in understanding how to run an Internet facing server, you better use a hosting service.
IIS or Apache -- the issues are the same. Your windows background makes IIS ideal. Checkout Ruby on Rails also. http://www.rubyonrails.org/. Paul Watson is the resident expert on this subject.
Thomas
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|