|
Whether it is getting deleted fro database?
Cheers!!
Brij
|
|
|
|
|
No brij,
its not delete from database...
thanx.....
|
|
|
|
|
use ExecuteNonQuery() for deleting from Database.If it gets deleted then bind again with the Grid
Cheers!!
Brij
|
|
|
|
|
Hi prem,
Use MyCommand.ExecuteNonQuery();
and after deleting Bind the grid again .
Try Karke Dekho , Koi Problem ho toh reply karna
|
|
|
|
|
hi,nishant
MyCommand.ExecuteNonQuery()
is also not giving output...
any other sol plz....
once go through the code:
protected void btnDelete_Click(object sender, EventArgs e)
{
// This variable contains the selected rows in the format 1,2,3
string SelectedRows = GetSelected();
// User defined function that calls the stored proc to delete the selected items
DeleteRows(SelectedRows);
}
public static void DeleteRows(string PTittle)
{
SqlConnection MyConnection = new SqlConnection("server=(local);database=BlogDatabase;UID=sa;PWD=meritinfo;");
SqlCommand MyCommand = new SqlCommand("Delete from Posts where PTittle=@PTittle ", MyConnection);
MyCommand.Parameters.Add(new SqlParameter("@PTittle", PTittle));
MyCommand.CommandType = CommandType.Text;
MyCommand.Connection.Open();
//SqlDataReader dr = null;
//dr = MyCommand.ExecuteReader();
//dr.Close();
MyCommand.ExecuteNonQuery();
//DataTable Posts = new DataTable();
//DataTable dt = new DataTable();
//dt.Load(dr);
//if (dt != null)
//{
// Posts = dt;
//}
}
|
|
|
|
|
Aise Likho
SqlConnection MyConnection = new SqlConnection("server=(local);database=BlogDatabase;UID=sa;PWD=meritinfo;");
SqlCommand MyCommand = new SqlCommand("Delete from Posts where PTittle=@PTittle ", MyConnection);
MyCommand.Parameters.Add(new SqlParameter("@PTittle", PTittle));
MyCommand.CommandType = CommandType.Text;
MyCommand.Connection=MyConnection;
MyConnection.open();
MyCommand.ExecuteNonQuery();
Aise Chala kar ke Dekho
|
|
|
|
|
sorry yaar ,
still not...
i think in DeleteRow(______), the parameter should empty
couz connection and commands are all ok..
what do u think..
thank for ur help....
|
|
|
|
|
Are u sending string of Selected Rows like
Ptittle="1,2,3,5" Like this ???
If like that then ur Delete Query dosen't work
becuase it will be like that
"Delete from Posts where Ptittle=1,2,3,5"
This won't work
Write like that
"Delete from Posts where Ptittle In ("+@Ptittle+")"
mein Salah doonga ki
Debug the Code and see What is the Command text
|
|
|
|
|
see yaar.
at MyCommand.ExecuteNonQuery ....SqlException raised--->Incorrect Syntax near ','
command text=
Delete from Posts where PTittle In (,)
|
|
|
|
|
good evening ,
i am trying new code now....here i can bring all checkbox selected fields PTittle value in a string gvID's...and passing to delete command...
but at ExecuteNonQuery() the Error raised that Incorrect Syntax near gvID's value...(for eg:Political Influence on Students is the value in
the string contains PTittle Values Collection...saying Syntax Error near Influence....
Here is the Code: .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="PTittle">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="CheckAll" onclick="return check_uncheck (this );" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="tittle" Visible="false"
Text='<%# DataBinder.Eval (Container.DataItem, "PTittle") %>' runat="server" />
<input type="checkbox" id="deleteRec" onclick="return check_uncheck (this );" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
<asp:BoundField DataField="PTittle" HeaderText="PTittle" SortExpression="PTittle" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />
<asp:BoundField DataField="Tags" HeaderText="Tags" SortExpression="Tags" />
<asp:BoundField DataField="PStatus" HeaderText="PStatus" SortExpression="PStatus" />
<asp:BoundField DataField="TotalComments" HeaderText="TotalComments" SortExpression="TotalComments" />
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClientClick="return confirmMsg(this.form)" Text="Button" OnClick="Button1_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BlogDatabaseConnectionString %>"
SelectCommand="SELECT [Author], [Date], [PTittle], [Category], [Tags], [PStatus], [TotalComments] FROM [Posts]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
<script type="text/javascript" language="javascript" >
function check_uncheck(Val)
{
var ValChecked = Val.checked;
var ValId = Val.id;
var frm = document.forms[0];
for (i = 0; i < frm.length; i++)
{
if (this != null)
{
if (ValId.indexOf('CheckAll') != - 1)
{
if (ValChecked)
{
frm.elements[i].checked = true;
}
else
{
frm.elements[i].checked = false;
}
}
else if (ValId.indexOf('deleteRec') != - 1)
{
if (frm.elements[i].checked == false)
{
frm.elements[1].checked = false;
}
}
}
}
}
function confirmMsg(frm)
{
for (i = 0; i < frm.length; i++)
{
if (frm.elements[i].name.indexOf("deleteRec") != - 1)
{
if (frm.elements[i].checked)
{
return confirm("Are you sure you want to delete your selection(s)?")
}
}
}
}
</script>
Here is the Code: .aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string gvIDs = "";
bool chkBox = false;
//'Navigate through each row in the GridView for checkbox items
foreach (GridViewRow gv in GridView1.Rows)
{
HtmlInputCheckBox deleteChkBxItem = (HtmlInputCheckBox)gv.FindControl("deleteRec");
if (deleteChkBxItem.Checked)
{
chkBox = true;
// Concatenate GridView items with comma for SQL Delete
gvIDs += ((Label)gv.FindControl("tittle")).Text.ToString() + ",";
}
}
SqlConnection cn = new SqlConnection(SqlDataSource1.ConnectionString);
if (chkBox)
{
// Execute SQL Query only if checkboxes are checked to avoid any error with initial null string
try
{
//string deleteSQL = "DELETE from Posts WHERE PTittle IN (" + gvIDs.Substring(0, gvIDs.LastIndexOf(",")) + ")";
SqlCommand cmd = new SqlCommand("DELETE from Posts WHERE PTittle IN (" + gvIDs.Substring(0, gvIDs.LastIndexOf(",")) + ")", cn);
cn.Open();
cmd.ExecuteNonQuery();//Error:After ExecuteNonQuery
GridView1.DataBind();
}
catch (SqlException err)
{
Response.Write(err.Message.ToString());
}
finally
{
cn.Close();
}
}
}
}
|
|
|
|
|
Is there any remort logger file for remote desktop connection? I have to handle add/update/deletion of the log details.
Is it possible?Plz advice and update me.
Muthu
|
|
|
|
|
Pls be so kind to use google with the query: "log4net"...
|
|
|
|
|
I think you can get details using WMI. but why in Asp.net ?
|
|
|
|
|
Is there any build-in function available in .Net framework, which accepts some number and returns a string
value equalent to the number?
[For ex: ReturnEqualentWord(int num); while passing, 5, it should return me Fifth,while 12, it should result twelve or twelvth.]
Muthu
|
|
|
|
|
|
.Net framework doesn't provide this but you can make your own custom function.
Cheers!!
Brij
|
|
|
|
|
I am trying to do file handling through jscript. While trying to create an object, it produces an error saying,
Automation server can't create object.While trying to use File Handling mechanism using js [through FileSystemObject]
Muthu
|
|
|
|
|
Looks like the ActiveX component could not be loaded...
Pls provide the code to get a more specific answer.
|
|
|
|
|
function callWriter(){
var fileSysObj = new ActiveXObject('Scripting.FileSystemObject');
var fileObj = fileSysObj.OpenTextFile("C:\\FromJs.txt",2,true,0);//2-overwrite,true-create if not exist,0-ASCII
fileObj.write('File written from Javascript');
fileObj.close();
}
so when i call the above function the error msg is thrown. should i do any thing in browser settings?
Muthu
|
|
|
|
|
Hi Muthu,
first of all you should check the browser settings, if ActiveX is enabled etc.
If this doesn't help, it is possible that the DLL containing the ActiveX is not registered properly. (but here it seems to be a system dll, that
's why it should be registered already).
Regards
Sebastian
|
|
|
|
|
tx pal, it works..
Muthu
|
|
|
|
|
how to use AL(Assembly Linker.exe) in command prompt. I have a dll called sample.dll
now i have to put it in GAC(Global Assembly Cache]. I tried with possible arguments like
AL sample.dll
AL /out:sample.dll
AL /out:Program.exe /link:sample.dll
i couldn't attain a solution.
Could any one tell me how to use it, with sample parameters?
Note:AL is used to create shared assemblies and it includes our assembly in WINNT\assembly folder of local machine.
Muthu
|
|
|
|
|
Hi Muthu,
please be more specific, what do you want to achieve exactly?
Regards
Sebastian
|
|
|
|
|
Dear Buddy,
The concept is we can create our own namespaces/assemblies and include it in current systems assembly folder.
So that the namespace is globally available any where to access. There is a command in AL which accepts our
dll and includes it automatically in GAC.That's it.
Muthu
|
|
|
|
|
Hi i want to change the date time format form 0-12 to 0-24
I want to do it programatically , Please help me in this
thanks and Regards
Sindhu Tiwari
* I dont want to change regional settings *
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|