|
|
There's a HOWTO[^] on MSDN. It uses a "local data cache", which means that it's actually looking up the details in a local database.
Wouldn't it be easier to simply put some name/passwords in a normal database and authenticate against that?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The reason i want to use the ASP.NET SqlMembershipProvider is because in the near future, an ASP.NET application will be developed off the same database and the user access rules and permissions will be required to be the same as in this win forms application.
|
|
|
|
|
EricCiz wrote: an ASP.NET application will be developed off the same database Start with the ASP.NET application; it doesn't need to do much, except allow you to login. That way it'll be easier to integrate the WinForm app on the authentication-mechanism of the ASP.NET app, since you'd be re-using the existing structure.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I am developing an application in which various forms are available and user had to add details on that forms and save in sql.on every form i have to save 5-6 textbox data.should i use executenonquery or execute scalar. also want to know the difference between two.
|
|
|
|
|
|
thanks for the help
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
resetLabels();
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\patientdb.mdf;Integrated Security=True;User Instance=True";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "select convert(varchar(50),getdate(),105) as date";
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
date = sdr["date"].ToString();
}
sdr.Close();
setPatientidtxt();
if (updateflag)
{
cmd.CommandText = "update Patient set" +
" name=@FirstName,surname=@LastName,age=@Age,city=@City,gender=@Gender,allergy=@Allergy,phoneno=@ContactNo,consultingfees=@Fees,note=@Note,date=@Date,time=@Time" +
" where patientid=@Patientid";
cmd.Parameters.AddWithValue("@patientid",textBox1.Text);
}
else
{
cmd.CommandText = "insert into patient values" +
"(@FirstName,@LastName,@Age,@City,@Gender,@Allergy,@ContactNo,@Fees,@Note,@Date,@Time)";
}
cmd.Parameters.AddWithValue("@FirstName", textBox2.Text);
cmd.Parameters.AddWithValue("@LastName", textBox3.Text);
cmd.Parameters.AddWithValue("@Age", textBox4.Text);
cmd.Parameters.AddWithValue("@City", textBox5.Text);
//radio button
if (radioButton1.Checked == true)
{
cmd.Parameters.AddWithValue("@Gender", radioButton1.Text);
}
else
{
cmd.Parameters.AddWithValue("@Gender", radioButton2.Text);
}
if (radioButton3.Checked == true)
{
cmd.Parameters.AddWithValue("@Allergy", radioButton3.Text);
}
else
{
cmd.Parameters.AddWithValue("@Allergy", radioButton4.Text);
}
cmd.Parameters.AddWithValue("@ContactNo", textBox6.Text);
cmd.Parameters.AddWithValue("@Fees", textBox7.Text);
cmd.Parameters.AddWithValue("@Note", textBox8.Text);
cmd.Parameters.AddWithValue("@Date", System.DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@Time", System.DateTime.Now.ToLongTimeString());
// here the exception error (break) is comming at ExecuteNonQuery)
cmd.ExecuteNonQuery();
button4.Enabled = true;
label11.Visible = true;
label4.Visible = true;
timer1.Start();
}
}
I am getting an error as :
"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Column name or number of supplied values does not match table definition."
and sequence of columns in my table is (patientid,name,surname,age,city,gender,allergy,phoneno,consultingfees,note,date,time)
i am wondering where is sequence wrong in my code. .
|
|
|
|
|
for insert add column names before values keyword like below
cmd.CommandText = "insert into patient (patientid,name,surname,age,city,gender,allergy,phoneno,consultingfees,note,date,time) values" +
"(@FirstName,@LastName,@Age,@City,@Gender,@Allergy,@ContactNo,@Fees,@Note,@Date,@Time)";
check column name and paremeter sequence. they should math number and each columns datatype should match with parametere
|
|
|
|
|
Hi,
thanks for the help code worked for my project!!!
but the thing is i added "insert into patient (patientid,......)values"+
"(@Patientid,....)"; the problem is that i fire a query in sql server to check the data is saved or not it was not there.
and thouh i typed the patient id manually in form..it will be disabled when i run application.only when i made it enable it was showing no error.
|
|
|
|
|
Hi,
i am not getting you point. If you provide proper parameter values in SQL then it has to work in SQL as well.
By the way , if my previous posts helped you then please up vote it. (green triangular button)
|
|
|
|
|
The clues are actually in the names. As you have probably guessed, ExecuteNonQuery is used for executing something that is not a query, i.e. an INSERT , UPDATE or DELETE . ExecuteScalar is used to return a scalar value from a query - a scalar is simply a single value. As a scalar is a single value, it requires less code than issuing something like ExecuteReader because the value is available for you to use immediately.
|
|
|
|
|
I just realised why my DAL only uses GetTable for 90% of our work, I get the inserted/updated record returned, as almost all my tables have a view this is the simplest way of getting all the related info. Delete and processing procs are the only exception and they return ints
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks for the help
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
resetLabels();
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\patientdb.mdf;Integrated Security=True;User Instance=True";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "select convert(varchar(50),getdate(),105) as date";
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
date = sdr["date"].ToString();
}
sdr.Close();
setPatientidtxt();
if (updateflag)
{
cmd.CommandText = "update Patient set" +
" name=@FirstName,surname=@LastName,age=@Age,city=@City,gender=@Gender,allergy=@Allergy,phoneno=@ContactNo,consultingfees=@Fees,note=@Note,date=@Date,time=@Time" +
" where patientid=@Patientid";
cmd.Parameters.AddWithValue("@patientid",textBox1.Text);
}
else
{
cmd.CommandText = "insert into patient values" +
"(@FirstName,@LastName,@Age,@City,@Gender,@Allergy,@ContactNo,@Fees,@Note,@Date,@Time)";
}
cmd.Parameters.AddWithValue("@FirstName", textBox2.Text);
cmd.Parameters.AddWithValue("@LastName", textBox3.Text);
cmd.Parameters.AddWithValue("@Age", textBox4.Text);
cmd.Parameters.AddWithValue("@City", textBox5.Text);
//radio button
if (radioButton1.Checked == true)
{
cmd.Parameters.AddWithValue("@Gender", radioButton1.Text);
}
else
{
cmd.Parameters.AddWithValue("@Gender", radioButton2.Text);
}
if (radioButton3.Checked == true)
{
cmd.Parameters.AddWithValue("@Allergy", radioButton3.Text);
}
else
{
cmd.Parameters.AddWithValue("@Allergy", radioButton4.Text);
}
cmd.Parameters.AddWithValue("@ContactNo", textBox6.Text);
cmd.Parameters.AddWithValue("@Fees", textBox7.Text);
cmd.Parameters.AddWithValue("@Note", textBox8.Text);
cmd.Parameters.AddWithValue("@Date", System.DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@Time", System.DateTime.Now.ToLongTimeString());
// here the exception error (break) is comming at ExecuteNonQuery)
cmd.ExecuteNonQuery();
button4.Enabled = true;
label11.Visible = true;
label4.Visible = true;
timer1.Start();
}
}
I am getting an error as :
"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Column name or number of supplied values does not match table definition."
and sequence of columns in my table is (patientid,name,surname,age,city,gender,allergy,phoneno,consultingfees,note,date,time)
i am wondering where is sequence wrong in my code. .
|
|
|
|
|
|
Hi,
I am dynamically adding text to pdf file using ColumnText.ShowTextAligned method. I want to show dynamic text vertically top left. Is there any solution?
|
|
|
|
|
it might others help you, if you showed the code and explained what SDK/toolkit you were using to perform this task
'g'
|
|
|
|
|
Hi,
Below is the code i am using.
using (FileStream stream1 = File.Open(DestinationPath + "\\" + Path.GetFileName(SourceFilePath), FileMode.Open))
{
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
//reader = new PdfReader(DestinationPath + "\\" + Path.GetFileName(SourceFilePath));
var pageSize = reader.GetPageSize(1);
PdfStamper stamper = new PdfStamper(reader, stream1);
iTextSharp.text.Font tmpFont = new iTextSharp.text.Font(bf, 9);
Phrase ph = new Phrase();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfContentByte canvas = stamper.GetOverContent(i);
ph = new Phrase(NewBatesStatmpingText, tmpFont);
ph.Font = tmpFont;
canvas.SetFontAndSize(bf, 9);
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, ph, SCX, SCY, 0);
}
|
|
|
|
|
When the query is work will call an insert query but when it is fail will appear a message that the record didn't founded in database
|
|
|
|
|
And what is your question? I can't see one in there at all.
|
|
|
|
|
when the query is false how can i take the result so i can use it for doing something else with this
|
|
|
|
|
What query? How is it returning false? You haven't shown a query.
|
|
|
|
|
OleDbConnection dbConnDest;
dbConnDest = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= SystemA.accdb");
string query_select = "SELECT ReferenceYear FROM [MS Access;DATABASE=" + dialog.FileName +"].Questionnaires_Table1 Where ReferenceYear = '" + dateref.Text + "';";
OleDbCommand cmd_year = new OleDbCommand(query_select, dbConnDest);
dbConnDest.Open();
string rfyear = cmd_year.ExecuteScalar().ToString();
|
|
|
|
|
So all you're doing is testing to see if ReferenceYear exists? Why not just do SELECT Count(1)... instead, and then just evaluate the count? If it's zero, the record doesn't exist? Also, you may want to pay attention to the fact your select statement is vulnerable to a SQL Injection attack.
|
|
|
|
|