|
I want to use a Gridview for a standard CRUD app.
So far I have my delete event wired up but I have a problem with my stored proc. I receive this error everytime i run my debugger and click the delete event. I have a catch event to catch this error.
The SqlParameterCollection only accepts non-null SqlParameter type objects, not Parameter objects.
Here is the code for my deleterow event. Any help is appreciated.
protected void DeleteRow(object sender, GridViewDeleteEventArgs e)
{
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = ConfigurationManager.ConnectionStrings["PokerTraxConnectionString"].ToString();
connection.Open();
SqlCommand delCommand = new SqlCommand();
delCommand.Connection = connection;
delCommand.CommandText = "usp_Delete_Loan";
delCommand.CommandType = CommandType.StoredProcedure;
delCommand.Parameters.Add(new Parameter("LoanId"));
delCommand.ExecuteNonQuery();
SqlDataAdapter adapter = new SqlDataAdapter(delCommand);
DataSet ds = new DataSet();
GridView1.DataSource = ds;
adapter.Fill(ds);
Cache["Loan"] = ds;
BindPlayerNames();
connection.Close();
connection.Dispose();
delCommand.Dispose();
}
catch (Exception ex)
{
errorMessage.Text = ex.Message;
}
}
|
|
|
|
|
This could be that the parameter was not created completey. In code that I have used I set other values for parameter object.
Generic stored proc calling code:
Dim command As New System.Data.SqlClient.SqlCommand
command.Connection = m_sqlConnection
command.CommandText = strStoredProc
command.CommandType = CommandType.StoredProcedure
' declare the parameter object
Dim param As System.Data.SqlClient.SqlParameter
Dim myEnumerator As System.Collections.IEnumerator = _
parameterArray.GetEnumerator()
Dim pItem As ParameterItem
While myEnumerator.MoveNext()
pItem = CType(myEnumerator.Current, ParameterItem)
' Add a new parameter, get back a reference to it
param = command.Parameters.Add(pItem.Name, pItem.Type)
' set the parameter's direction and value
param.Direction = pItem.Direction
param.Value = pItem.Value
End While
Dim myDataAdapter As New SqlClient.SqlDataAdapter
command.CommandTimeout = iTimeOut
myDataAdapter.SelectCommand = command
myDataAdapter.Fill(ds, "ResultSet")
|
|
|
|
|
Perhaps I should have mentioned I wrote this in C#.net. Thanks for the help though I can kindve determine how this is supposed to work.
|
|
|
|
|
Dear sir,
i have created a form with 3 textbox controls and a button called transfer
I have a table named CustId with the following records:
CID BAL
1 30000
2 50000
Here when i enter any amount (i.e, 3000) in TextBox1 and
enter the CID number(2) in the TextBox3 and click on the transfer button
The record bearing CID as 2 should be updated (the balance in this case will be 50000-3000=47000)
similarly,
if i enter any amount (i.e, 2000) in TextBox2 and
enter the CID number(1) in the TextBox3 and click on the transfer button
The record bearing CID as 1 should be updated (the balance in this case will be 30000-2000=32000)
i have already written the coding for that . But when i try to execute it
it gives a error , that is
"Line 1 Incorrect sytax near = "
Pl see the code below
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace data1
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
SqlConnection cn;
SqlCommand dbcm,crcm;
string dbcmstr,crcmstr;
int i1,i2;
SqlTransaction tr;
private void button1_Click(object sender, System.EventArgs e)
{
try
{
cn = new SqlConnection("user id = sa;initial catalog=pubs");
dbcmstr = string.Format("update custdb set bal=bal-{0}where cid={1}",textBox3.Text,textBox1.Text);
crcmstr = string.Format("update custdb set bal=bal+{0}where cid={1}",textBox3.Text,textBox2.Text);
dbcm=new SqlCommand(dbcmstr,cn);
crcm=new SqlCommand(crcmstr,cn);
cn.Open();
tr=cn.BeginTransaction();
dbcm.Transaction=tr;
i1=dbcm.ExecuteNonQuery();
crcm.Transaction=tr;
i2=crcm.ExecuteNonQuery();
if(i1==1 && i2==1)
{
tr.Commit();
MessageBox.Show("sucsesfull");
}
else
{
tr.Rollback();
MessageBox.Show("Failure");
}
cn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
pl help me out with this
Thank u very much
arun
|
|
|
|
|
Arun Hegde wrote: TextBox1
Arun Hegde wrote: TextBox3
You might want to give more meaningful names to your text boxes. Your code is not maintainable.
dbcmstr = string.Format("update custdb set bal=bal-{0}where cid={1}",textBox3.Text,textBox1.Text);
There is no space betweeen the injected value at {0} and where so the SQL statement will expand to:
update custdb set bal=bal-3000where cid=2
I strongly suggest you look into the subject of SQL Injection Attacks because your code is highly susceptable. SQL Injection Attacks and Some Tips on How to Prevent Them[^]
|
|
|
|
|
If somebody have the form or code pls.send me because I am new in this.
|
|
|
|
|
lopa12 wrote: have the form or code
Sorry, don't have any. Shouldn't be that difficult to do. Use some creativity
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
Hello there, I'm currently creating an application that will work as a workout journal. One part of this will be reporting your exercices. I will have a list of avaliable exercices which the user can choose one from and fill in the necessary information.
Now, at first I thought it was easy with just two tables. One for each filled in exercice connected to a user and one for all avaliable exercices. However the problem is that while all exercices have a name they differ in other variables. Pushups for example are just repetitions, benchpress is repetition and weight, running is distance and length. Etc etc. How would I solve this in the best way?
Having one table with all avaliable exercices and variables and just having NULL when the field is supposed to be empty? Splitting them up to different tables might be difficult as I would like to add new exercices without having to remake the database if I happened to miss one combination.
Thank you in advance and hope you understood my rambling.
|
|
|
|
|
Christer Claesson wrote: Having one table with all avaliable exercices and variables and just having NULL when the field is supposed to be empty? Splitting them up to different tables might be difficult as I would like to add new exercices without having to remake the database if I happened to miss one combination.
Splitting the information into tables is probably the best way - one table detailing all the variables, one table containg the excercises and another table with the link between the two (one to many relationship).
Hope this helps
Chandra Ram
|
|
|
|
|
Samuel G wrote: trying to connect to mysql database on my hosting account godaddy
Do they allow you to connect remotely to the database?
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
No they don't,
but it is a test page that I have uploaded to my hosting server
Samuelg
-- modified at 2:22 Wednesday 22nd November, 2006
|
|
|
|
|
Samuel G wrote: it is a test page that I have uploaded to my hosting server
Might be an issue on their part. Have you tried contacting their support people?
|
|
|
|
|
I manage to get it right so godaddy does support mysql for asp.net
my connection string was wrong I'v used there IP Address not there server name
ooops my mistake!!
SamuelG
|
|
|
|
|
The OLE DB provider "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Providers\OLEDB\Microsoft.Jet.OL
EDB.4.0" has not been registered.
I've tried this also,
EXEC sp_addlinkedserver 'ExcelSource',
'Jet 4.0',
'Microsoft.Jet.OLEDB.4.0',
'C:\Documents and Settings\viswanatha_c\Desktop\Book1.xls',
NULL,
'Excel 5.0'
Error:
User does not have permission to perform this action.
srinivasintouch
|
|
|
|
|
srinivasintouch wrote: The OLE DB provider "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Providers\OLEDB\Microsoft.Jet.OL
EDB.4.0" has not been registered.
Have you fixed this problem?
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
Hello everyone,
In my C# program I load an XML file to a dataset. It has elements called "page". Three of its nodes are year, month and day.. I want to write a query that whenever a user gives two different dates, the query should select the "page"s which's date fall between the given dates.
How can I achieve this. I tried a lot but while I am a rookie I couldn't find a solution. Also google doesn't help.
Thanks for your helps and best regards.
.:: Something is Wrong ::.
|
|
|
|
|
SELECT * FROM MyTable WHERE DateColumn > @startDate AND DateColumn <@endDate
If that is not the answer you are looking for, then perhaps you could explain which part you are stuck on.
|
|
|
|
|
Well, the problem is thatI haven't got any DateColumn.. There are three columns named year, month and date..
Anyway, I have solved it. I wrote a query like this :
<br />
dateQuery = "((year > '" + date.Year.ToString() + "') AND (year < '" + date2.Year.ToString() + "')) "<br />
+ "OR ((year = '" + date.Year.ToString() + "') AND (month > '" + date.Month.ToString() + "')) " <br />
+ "OR ((year = '" + date.Year.ToString() + "') AND (month = '" + date.Month.ToString() + "') AND (day > '" + date.Day.ToString() + "')) "<br />
+ "OR ((year = '" + date2.Year.ToString() + "') AND (month < '" + date2.Month.ToString() + "')) " <br />
+ "OR ((year = '" + date2.Year.ToString() + "') AND (month = '" + date2.Month.ToString() + "') AND (day < '" + date2.Day.ToString() + "')) ";<br />
It seems a bit confusing, but it do the job
Thanks a lot for your helps..
.:: Something is Wrong ::.
|
|
|
|
|
I havent really gone thru your query. Why not just do something simpler, so that your query is more readable in the future or to someone who is seeing your code.
<br />
WHERE Convert(datetime,day + '/' + month + '/' + year,103) >= '"+ date.ToString() +"' AND <br />
Convert(datetime,day + '/' + month + '/' + year,103) < '"+ date2.ToString() +"' .......<br />
Just an example, you may have to rewrite the query to your need.
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
Experience is like a comb that life gives you when you are bald - Navjot Singh Sidhu
|
|
|
|
|
That is a better solution - but still potentially suscepatable to a SQL Injection Attack. Consider the use of parameters rather than injecting values into the string.
|
|
|
|
|
Colin Angus Mackay wrote: Consider the use of parameters
And of course, read your article on SQL Injection Attacks
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
when i m trying to connect my c# application with Sql Server then a message is coming as"SQLNCLI.1" provider is not registered on the local machine. Any solution
sincerly
shriya
|
|
|
|
|
Do you have native client (client tools) installed on your local machine?
|
|
|
|
|
Hello,
I am using a report that has 2 subreports and when I create a 3rd it does not display any data on the form where they should be in the other 2 subreports.
My code is below.
I if take 1 subreport off and leave the other 2 then the report will display the data. but if i add another one then it displays nothing in the other 2 subreports.
I have used typed dataset. I don't have any groups, and deleted the links in the database expert of the report.
<br />
report.Load(Application.StartupPath & "/rptJobSheet5.rpt")<br />
<br />
report.SetDataSource(DS_JobSheet2)<br />
report.Subreports.Item(0).SetDataSource(DS_JobSheet2.Tables("IncidentTask"))<br />
report.Subreports.Item(1).SetDataSource(DS_JobSheet2.Tables("Supportcontracts"))<br />
report.Subreports.Item(2).SetDataSource(DS_JobSheet2.Tables("Client"))<br />
<br />
Me.CrystalReportViewer1.ReportSource = report<br />
Another quick question:
item(0) what name would this be in the properties of the subreport. I create the subreport using the wizard and have called it Client. but if i do this item("client") it shows an error. Also I have tried changing the name to this in the subreport properites | name. Should I use the index of the name property.
Thanks in advance,
Steve
|
|
|
|
|
Hello,
Is there anyway to append some value to colunm name? For example, i have table with 150 colunms and i want to do Select * and append today's date with each colunm name. So column1, column2... should display colunm1_112006, column2_112006 and so on etc. I'll appreciate any help.
Thanks in advance.
|
|
|
|