این دستور SQL درست هست یا خیر
SqlDataAdapter cmd = new SqlDataAdapter("select firstname,lastname,username,price,operator,type,score,number,idchat,State,ResNum,RefNum,saleOrderId,OffPercent,InvoiceId,RegisterDate from [report] where firstname ='" + TextBox3.Text + "' or lastname='" + TextBox4.Text + "' or username='" + TextBox5.Text + "' or price = '" + TextBox6.Text + "' or operator ='" + DropDownList1.SelectedItem.Text + "' or type = (type='" + DropDownList2.SelectedItem.Text + "'or type='" + DropDownList5.SelectedItem.Text + "' or type='" + DropDownList6.SelectedItem.Text + "') or score = (score='" + DropDownList4.SelectedItem.Text + "' or score='" + DropDownList7.SelectedItem.Text + "') or number = '" + TextBox7.Text + "' or idchat = '" + TextBox11.Text + "' or State ='" + TextBox12.Text + "' or ResNum ='" + TextBox13.Text + "' or RefNum='" + TextBox14.Text + "' or saleOrderId = '" + TextBox8.Text + "' or OffPercent = '" + TextBox15.Text + "' or InvoiceId = '" + TextBox16.Text + "'", con);
به نظر درست میاد ولی از نظر امنیت 0 هست
نباید پارمتر ها را در خود کوئری بدید و باید به صورت @ استفاده کنید
در باره این نوع کوئری نوشتن که شما میگید اطلاعاتی ندارم .
اگر منبعی وجود داره لطفا معرفی کنید
ممنون
// Update the demographics for a store, which is stored // in an xml column. string commandText = "UPDATE Sales.Store SET Demographics = @demographics " + "WHERE CustomerID = @ID;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(commandText, connection); command.Parameters.Add("@ID", SqlDbType.Int); command.Parameters["@ID"].Value = customerID; // Use AddWithValue to assign Demographics. // SQL Server will implicitly convert strings into XML. command.Parameters.AddWithValue("@demographics", demoXml); try { connection.Open(); Int32 rowsAffected = command.ExecuteNonQuery(); Console.WriteLine("RowsAffected: {0}", rowsAffected); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
این لینک رو هم ببینید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)