数据未输入数据库 [英] data is not entering in database
本文介绍了数据未输入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是类DAL中的方法
This is the method in class DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
public static SqlConnection con;
public static SqlCommand com;
public static SqlDataAdapter ad;
public static DataSet ds;
public static int affectedRows;
public static string strConnectionString;
static DAL()
{
strConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["dbsFALancing"].ConnectionString;
con = new SqlConnection(strConnectionString);
com = new SqlCommand();
com.Connection = con;
ad = new SqlDataAdapter(com);
affectedRows = -1;
}
public static void InsertUpdateDelete(string strQuery)
{
com.CommandText = strQuery;
try
{
con.Open();
affectedRows = com.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
public static DataSet SelectData(string strQuery)
{
ds = new DataSet();
com.CommandText = strQuery;
try
{
con.Open();
ad.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
return ds;
}
}
在按钮后面单击,我有要插入的代码.
behind button click i have this code for insertion.
DAL.InsertUpdateDelete(@"insert into tblFrProject(PostedBy, CategoryID, Title, Detail, MaxBidAmount, OpeningDate, ClosingDate, PostedDate, Requirements, Status)
values(" + 2 + ", " + CategDropDownList.SelectedValue + ", ''" + txtProjectName.Text + "'',''" + txtDes.Text + "'',''" + txtOpeningDate.Text + "'',''" + txtOpenDays.Text + "'',''" + DateTime.Now + "'',''" + RequirmentsTextBox.Text + "''," + receiveNotification.Checked.ToString() + "");
推荐答案
由于查询本身存在错误,您会遇到一些语法错误.
尝试下面的一个...
You have some syntax errors due to error in the query itself.
Try the below one......
string strQuery = "insert into tblFrProject(PostedBy, CategoryID, Title, Detail, MaxBidAmount, OpeningDate, ClosingDate, PostedDate, Requirements, Status) values('2', '" + CategDropDownList.SelectedValue + "', '" + txtProjectName.Text + "', '" + txtDes.Text + "', '" + txtOpeningDate.Text + "', '" + txtOpenDays.Text + "', '" + DateTime.Now + "', '" + RequirmentsTextBox.Text + "', '" + receiveNotification.Checked.ToString() + "')";
DAL.InsertUpdateDelete(strQuery);
而且您的第一个值(即2)不是变量,但是您像
And your first value i.e. 2 is not a variable, but you have written like a variable like
values(" + 2 + ",
它应该像....
It should be like....
values('2',
让我知道它是否对您有用....
Let me know if it works for you or not....
正确输入半冒号和冒号
我找到了我使用的答案的朋友调试器向我显示查询中缺少的内容,谢谢朋友.
I find the answer friends i use debugger that shows me what i was missing in my query thanks friends.
这篇关于数据未输入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文