我是php和mysql的新手,所以我需要一些查询帮助.这是我的SQL查询
SELECT * FROM table1 WHERE (Name LIKE '%$keyword%' OR ZipCode LIKE '%$keyword%') AND Category LIKE '$category' AND Country LIKE '$country' LIMIT $start, $limit
Run Code Online (Sandbox Code Playgroud)
现在我想做的事情就是
换句话说,如果选择了关键字,国家或类别中的任何一个,则搜索应相应地显示结果.此外,如果输入所有字段,它也应该工作.我设法做了一半,但有时它给了我错误的结果.请帮忙.
private void button1_Click(object sender, EventArgs e)
{
// Início da Conexão com indicação de qual o servidor, nome de base de dados e utilizar
/* É aconselhável criar um utilizador com password. Para acrescentar a password é somente
necessário acrescentar o seguinte código a seguir ao uid=root;password=xxxxx*/
mConn = new MySqlConnection("Persist Security Info=False; server=localhost;database=FichasReparacao;uid=root");
// Abre a conexão
mConn.Open();
//Query SQL
MySqlCommand command = new MySqlCommand("INSERT INTO Cliente (nome, email, telefone, blacklist)" +
"VALUES('" + nome_cli.Text + "','" + email_cli.Text …Run Code Online (Sandbox Code Playgroud) 我有问题试图从我的VS 2012删除记录,我正在使用sql server 2012,这是我的讲师的任务,我无法解决它
现在这就是我的意思
Private Sub bt_hapus_Click(sender As Object, e As EventArgs) Handles bt_hapus.Click
Try
Dim sqlda As New SqlClient.SqlDataAdapter("Delete from tabelpasien where No_Rkm_Mds=" & Me.txt_rkm_mds.Text, Me.SqlConnection1)
sqlda.Fill(dspasien, "tabelpasien")
MsgBox("Data telah berhasil dihapus")
bersih()
pasif()
normal()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
任何帮助都会大大贬低......
我想获得顶级3根据安全数据行equipment,并plant从数据库中选择。现在我可以通过设备和工厂选择从数据库中获得前 3 个安全值并插入到文本框。
当我写"' or Safety '" + textbox.text +它时,它正在选择其他工厂和设备
sqlcon1.Open();
SqlDataAdapter Data = new SqlDataAdapter (@"select * from ****** Where "
+ "[Equipment Type]='" + equipmenttype_combobox.Text.Trim()
+ "' and Plant='" + plant_combobox.Text.Trim()
+ "' and Safety= '" + firstsafety_textbox.Text.Trim()
+ "' or Safety='" + secondsafety_textbox.Text.Trim()
+ "' or Safety='" + thirdsafety_textbox.Text.Trim() + "'", sqlcon);
DataTable dt1 = new DataTable();
SqlDataAdapter db1 = new SqlDataAdapter();
Data.Fill(dt1);
datagridview1.DataSource = dt1;
sqlcon1.Close();
Run Code Online (Sandbox Code Playgroud) 这是我的代码,由于某种原因,我是否为输入id指定了一个值,它似乎提供了一个,因为只运行if语句.此外,当我为id(或不)提供值时,不会更新或更改任何内容.
<?php
$culture = $_POST["culture"];
if (isset($_POST["id"])) {
$UID = $_POST["id"];
mysql_query("UPDATE culture SET cult_desc='$culture' WHERE cult_id=$UID");
echo $UID . " " . $culture . " If Statement Activated";
}
else {
mysql_query("INSERT INTO culture
VALUES(cult_desc='$culture')");
echo $culture . " Else Statement Activated";
}
?>
Run Code Online (Sandbox Code Playgroud)
这是html代码:
<form action="addculture.php" method="POST">
<span><input type="text" size="3" name="id" />
<input type="text" name="culture" />
<input type="submit" value="add" /></span>
</form>
Run Code Online (Sandbox Code Playgroud) 我多次检查我的SQL语句,似乎我的SQL语句是错误的.我不知道为什么它不起作用.我的SQL语句是正确的,它导致了这个OleDBException"UPDATE语句中的语法错误.".
这是代码
OleDbConnection CN = new OleDbConnection(mysql.CON.ConnectionString);
CN.Open();
cmd1 = new OleDbCommand("Update Mosque Set Name='" + txtNAME.Text + "', No='" + Convert.ToInt32(txtNO.Text) + "', place='" + txtPlace.Text + "', group='" + txtGroup.Text + "', description='" + txtdec.Text + "' where id='" + txtID.Text + "'", CN);
cmd1.ExecuteNonQuery();
CN.Close();
Run Code Online (Sandbox Code Playgroud)
需要帮助请知道这里的错误是什么
我正在尝试创建一个登录程序,该程序将使用保存在数据库中的用户名和密码来检查用户输入的内容.出于某种原因,程序中的"if(dr.HasRows)"部分无效.当我尝试没有尝试捕获,我得到并错误"可能错误的空声明".我做错了什么?
SqlConnection Connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Logins.mdf;Integrated Security=True");
try
{
Connection.Open();
MessageBox.Show("Connection Succesful");
if (Connection != null && Connection.State == ConnectionState.Closed);
SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM Logins WHERE Username='" + txtUsername.Text + "' and Password='" + txtPassword.Text + "'", Connection);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
MessageBox.Show("Login Success");
}
else
{
MessageBox.Show("Incorrect login");
}
}
catch (Exception)
{
MessageBox.Show("Connection Unsuccesful");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试dd-MM-yyyy在c#中以格式插入日期.查询插入是
SqlCommand cmd_cust = new SqlCommand(@"insert into custdetail values ('" + txtInvoiceNo.Text + "','" + txtCustomerName.Text + "','" + txt_contact.Text + "', '" + txtAddress.Text + "', '" + txt_total_amt.Text + "', '" + dt_date.Value.ToString("dd-MM-yyyy") + "')", con_create);
con_create.Open();
cmd_cust.ExecuteNonQuery();
con_create.Close();
Run Code Online (Sandbox Code Playgroud)
我创建了一个列名为date的表具有datatype date.插入记录后,日期列字段中的值为yyyy-dd-MM格式.我希望这种dd-MM-yyyy格式.
我试图在我的SQL Server数据库中插入1或0,我的数据类型是"位".我试过这样做,但它说错误的语法附近 -
dt=g1.ExecDB( insert into tbl ("check1,check2,check3") values('"
+ Convert.ToByte(check1.Checked) + "','"
+ Convert.ToByte(check2.Checked) + "','"
+ Convert.ToByte(check3.Checked) + "' ) )
where loginname = '"+Session["log"].ToString() + "'"
) ;
Run Code Online (Sandbox Code Playgroud)
请指导我在哪里做错了?
strSQL = "INSERT INTO Accounts UserName, Password VALUES ('" & txtUsername.Text & "', '" & txtEncryptedPassword & "');"
Run Code Online (Sandbox Code Playgroud)
当代码执行并抛出错误时,但是我没有看到可见的问题.救命!
c# ×6
sql ×5
mysql ×4
sql-server ×3
php ×2
vb.net ×2
bit ×1
checkbox ×1
database ×1
insert ×1
parameters ×1
search ×1
sqlcommand ×1
vb.net-2010 ×1