|
Hello,
I have a string with an email address.
I want to look at an Access database to see if there is any record with that email.
If there is a record I want to delete it. If there is no record I want to add a new one with that email address as value in field Email.
I allready have the connection defined in the web.config file.
Could someone tell me how to do this?
Thanks,
Miguel
|
|
|
|
|
SQL
create proc insertEmail
(@email varchar(50)) as
if exsist( select * from dbo.yourTable where
where email = @email )
delete dbo.yourTable where
where email = @email
else
begin
insert into dbo.yourTable
(email) select @email
end
C#
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "YourString";
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "insertEmail";
cmd1.Connection = conn;
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("@email", stringEmail))
conn.Open();
cmd1.ExecuteNonQuery();
conn.Dispose;
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Hello,
Is it possible to create this using the SQL code in a QueryString in Asp.Net?
It is just I am not used to use SQL procedures and I am not even sure if I can use them in an Access Database.
Thanks,
Miguel
|
|
|
|
|
You can use put a raw sql statement in a string for ADO.NET, but I would highly recommend against putting it in the query string, that would make it viewable to the entire world (and editable). The results would likely be catestrophic.
|
|
|
|
|
I would to suggest...
1) Take Count(*) From your table.
2) If record is greater than 0 then do delete action.
3) Finally U take insert action.
Other way,
1) Never checking the record and take delete action.
2) Finally insert action.
Anyway U can do as u like.
Cheer.
|
|
|
|
|
Hi, i have been going mad for days now, i cant seem to suss this problem out.
I have web.config forms authentication which authenticates normal pages fine.
The problem is when I try to run:
crystalreportviewer.reportsource = "myreportservice.asmx"
it gives me the dreaded "Object moved to here" link, the link then takes me to "myreportservice.asmx".
If i remove forms authentication, the report loads fine.
do i need to pass the logon credentials to the crystalreportviewer object?
I must be missing something very simple.
Please help.
|
|
|
|
|
Hello, everybody! I came to you with another problem. This time, it's about a dataset loading an .xml document and an authentification form: login.
<br />
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)<br />
{<br />
dsLogin ds_login = new dsLogin();<br />
ds_login.ReadXml(Server.MapPath("~/App_Data/login.xml"), System.Data.XmlReadMode.ReadSchema);<br />
Label1.Text = ""; <br />
<br />
for(int i =0; i<ds_login.Tables[0].Rows.Count; i++){<br />
<br />
Label1.Text = Login1.Password + " " + ds_login.Tables[0].Columns[2].Table.Rows[i].ToString(); <br />
if(Login1.UserName == "a") Label1.Text = Label1.Text +" 1 ";<br />
if(Login1.Password == "aaaaaa.") Label1.Text = Label1.Text + " 2 ";<br />
if(ds_login.Tables[0].Columns["UserName"].Table.Rows[i].ToString() == "a") Label1.Text = Label1.Text + " 3 ";<br />
if (ds_login.Tables[0].Columns[2].Table.Rows[i].ToString() == "aaaaaa.") Label1.Text = Label1.Text + " 4 ";<br />
<br />
if(Login1.UserName.Equals(ds_login.Tables[0].Columns["UserName"].Table.Rows[i].ToString()))<br />
<br />
if(Login1.Password.Equals(ds_login.Tables[0].Columns[2].Table.Rows[i].ToString()))<br />
<br />
{<br />
e.Authenticated = true;<br />
} <br />
}<br />
<br />
}<br />
the problem seems to be that the web never reaches the if-s. even thought i've set watches for both values there, nothing happened. more, at the test, i only get 1 and 2 and, instead the value at ds_login.Tables[0].Columns[2].Table.Rows[i].ToString(), i get System.Data.DataRow.
Please tell me what i do wrong!
Thanks in advance!
|
|
|
|
|
Hi,
I know with the "file upload" control you can upload files, but my question is, how can I delete those files, or delete a specific file from my hdd if I know the path, using asp.net?
|
|
|
|
|
System.IO.File.Delete("FilePath");
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks
Just one question. Will "FilePath" be the complete path from "C:\" or from within the application path on IIS or server?
EG http://localhost/invoices/mysheet.doc
|
|
|
|
|
Use the actually file path "C:\"
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
You can use Server.MapPath to translate from the relative path to the absolute.
You may run into permissions exceptions, just a heads up.
~A
|
|
|
|
|
It is true, we have a have web farm so we have two IIS servers running the same site. We can't even write files because the account running aspnet doesn't have access to the network drives. Users can't save files to local drives because it is two machines. After 2 years, I finally came up with a work around. I created a web service that impersonates a windows account and accepts a byte array as a parameter. I call the web service to write files to a networked directory that the impersonated account has access to. I should write an article about it.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Hi all,
I m using asp.net 2.0. I have queried the Database and having all my data in a DataSet (eg 'myDS').
If i ve use GridView control and Bind the DataSet, then the No. of Data Rows displayed in the GridView is same as the No. of Rows in the DataTable of DataSet (myDS).
But i wish to customize the no of GridView Rows, ie Reduce the no of rows. ( Displaying Multiple DataTable Row in a Single Row of GridView.)
For example, the GridView with 3 Columns in a Single row. Each Column Displays respective DataTable Value from myDS. Thereby reducing the no of rows of GridView by 1/3.
Anybody can help me achieve this?
Regards,
Jay
|
|
|
|
|
You can create a new datatable with 1/3 the number of rows. Do something like this.
DataTable dtOriginal = dst.Tables[0];
DataTable dtNew = new DataTable();
DataColumn c1 = new DataColumn();
DataColumn c2 = new DataColumn();
DataColumn c3 = new DataColumn();
string s = "1" ;
c1.ColumnName = "Row1";
c1.DataType = s.GetType();
c2.ColumnName = "Row2";
c2.DataType = s.GetType();
c3.ColumnName = "Row3";
c3.DataType = s.GetType();
dtNew.Columns.Add(c1);
dtNew.Columns.Add(c2);
dtNew.Columns.Add(c3);
int intRowID = 0;
string[] values = new string[3];
foreach (DataRow r in dtOriginal.Rows)
{
switch (intRowID)
{
case 0:
values[0] = r[0].ToString();
intRowID += 1;
break;
case 1:
values[1] = r[1].ToString();
intRowID += 1;
break;
case 2:
values[2] = r[2].ToString();
intRowID = 0;
DataRow rNew = dtNew.NewRow();
rNew[0] = values[0].ToString();
rNew[1] = values[0].ToString();
rNew[2] = values[0].ToString();
dtNew.Rows.Add(rNew);
break;
}
}
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks for your reply. It works fine. But my DataRow contains 4 string values. For that i have used two dimensional Jagged Array and got all the values from first three rows.
For this (Jagged Array values), how can i declare a DataColumn and Bind it to the 4 diff. server controls present in my GridView.
ie. Each Column in the GridView contains 4 no of server cntrols.
I need ur valuable suggestions.. Thanks.
Regards,
Jay
|
|
|
|
|
Put an Html table in your template column. Give each table cell an id and runat="server" then. E.G.
Then use the gridviews RowDataBound event.
gvRowDB(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
DataRowView drv = (DataRowView) e.row.DataItem();
HtmlTableCell td1 =("HtmlTableCell") e.Row.FindControl("td1");
td1.innerText = drv.item["YourColum"].toString();
}
}
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
i have a button that is contain the code that call the stored procedure .
the stored procedure is execute insert sql statment and add record to
the data base that is in sql server .
when i pressed the button the record is added well and go to the database.
the problem is when i click refresh for the browser on this page
the record is added again on the database .
why & how can solve this problem ?
dead
|
|
|
|
|
What happens is when an event gets fired(postback) the event source gets stored and when you clicks on the refresh button then the event gets again fired. One simple way to get rid of the problem is to redirect to the same page after execution of the event.
Best Regards,
Apurva Kaushal
|
|
|
|
|
thank you
this is working well
but the sqldatasource that read from database is dont work when i click refresh and i need to show the last data record inserted .
can i do this ?
dead
|
|
|
|
|
If i have understood your problem correctly then after inserting the data into the database you want to display the inserted data to the user. If this is the case then you can't directly redirect to the same page you send some value in the querystring and then in the load event of the page just check the querystring value if it is present then get the newly inserted data and display it.
Hope it will serve the purpose.
Best Regards,
Apurva Kaushal
|
|
|
|
|
thank you for help
>>>
>>>
dead
|
|
|
|
|
always welcome..
Best Regards,
Apurva Kaushal
|
|
|
|
|
First way is U control duplicate data for DB level.
Second way is U control the key event and take an action.
As U like
|
|
|
|
|
i need to write a code which would retrieve the information about the webcontrols in a webpage. i need to know the count and also what type of controls. i know that System.Reflection namespace can be used. but i do not know what class to use. can anybody help??
Sonu
|
|
|
|