TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
rachayita jaiswal
NA
217
106.8k
MySqlcommand parameters in asp.net
Aug 22 2013 5:06 AM
HI,
I have created StoredProcedure in Mysql -
CREATE PROCEDURE `SP_ValidateUser`(_action varchar(10), _userid varchar(150), _password varchar(100))
BEGIN
if _action = 'Validate' then
Select UserId, Password from table
where UserId = _userid and Password = _password;
end if;
END
and for calling SP i want to create a common Function so I have created like -
public DataTable GetCommonData(string SP, string action, string id, string str1, string str2)
{
DataTable dt = new DataTable();
strcon.Open();
MySqlCommand cmd = new MySqlCommand();
MySqlDataAdapter ad = new MySqlDataAdapter(cmd);
cmd.Connection = strcon;
cmd.CommandText = SP;
cmd.CommandType = CommandType.StoredProcedure;
string[] strcol = {action,id,str1,str2};
foreach (string str in strcol)
{
cmd.Parameters.AddWithValue("_action", str);
}
ad.Fill(dt);
ad.Dispose();
return dt;
}
for first value that is "action", it is taking value but while coming on second value it is showing error like -
cmd.Parameters.AddWithValue("_action", str);
"_action" already used ...
i can define saperate this line for each value but
i don't want to use many lines...
is there any issue in my code?
Please let me know.....
Reply
Answers (
5
)
RequiredFieldValidator in DataList
exception error